Skip to content

More crashes in class scoped imports #12197

Closed
@JelleZijlstra

Description

@JelleZijlstra

In Python 3 (but not Python 2), it is illegal to do import * in class body, but mypy allows it.

It also crashes if you do class X: from os import *:

% python -m mypy -c 'class Capybara: from os import *' --show-traceback
<string>:1: error: INTERNAL ERROR -- Please try using mypy master on Github:
https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 0.940+dev.1de5e55fff22b023d54aa700d630befd162db20e
Traceback (most recent call last):
  File "/Users/jelle/.pyenv/versions/3.9.4/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/Users/jelle/.pyenv/versions/3.9.4/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/Users/jelle/py/mypy/mypy/__main__.py", line 34, in <module>
    console_entry()
  File "/Users/jelle/py/mypy/mypy/__main__.py", line 12, in console_entry
    main(None, sys.stdout, sys.stderr)
  File "/Users/jelle/py/mypy/mypy/main.py", line 96, in main
    res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
  File "/Users/jelle/py/mypy/mypy/main.py", line 173, in run_build
    res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
  File "/Users/jelle/py/mypy/mypy/build.py", line 180, in build
    result = _build(
  File "/Users/jelle/py/mypy/mypy/build.py", line 256, in _build
    graph = dispatch(sources, manager, stdout)
  File "/Users/jelle/py/mypy/mypy/build.py", line 2722, in dispatch
    process_graph(graph, manager)
  File "/Users/jelle/py/mypy/mypy/build.py", line 3066, in process_graph
    process_stale_scc(graph, scc, manager)
  File "/Users/jelle/py/mypy/mypy/build.py", line 3158, in process_stale_scc
    mypy.semanal_main.semantic_analysis_for_scc(graph, scc, manager.errors)
  File "/Users/jelle/py/mypy/mypy/semanal_main.py", line 79, in semantic_analysis_for_scc
    process_functions(graph, scc, patches)
  File "/Users/jelle/py/mypy/mypy/semanal_main.py", line 233, in process_functions
    process_top_level_function(analyzer,
  File "/Users/jelle/py/mypy/mypy/semanal_main.py", line 274, in process_top_level_function
    deferred, incomplete, progress = semantic_analyze_target(target, state, node, active_type,
  File "/Users/jelle/py/mypy/mypy/semanal_main.py", line 326, in semantic_analyze_target
    analyzer.refresh_partial(refresh_node,
  File "/Users/jelle/py/mypy/mypy/semanal.py", line 416, in refresh_partial
    self.accept(node)
  File "/Users/jelle/py/mypy/mypy/semanal.py", line 5199, in accept
    node.accept(self)
  File "/Users/jelle/py/mypy/mypy/nodes.py", line 730, in accept
    return visitor.visit_func_def(self)
  File "/Users/jelle/py/mypy/mypy/semanal.py", line 607, in visit_func_def
    for arg in defn.arguments:
AttributeError: arguments
<string>:1: : note: use --pdb to drop into pdb

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions