Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mypy crashes with from .. import * import #4111

Closed
matzipan opened this issue Oct 13, 2017 · 1 comment
Closed

Mypy crashes with from .. import * import #4111

matzipan opened this issue Oct 13, 2017 · 1 comment

Comments

@matzipan
Copy link

matzipan commented Oct 13, 2017

In my example at #4110 , if I change the import in backends/Bla.py to from .. import * and remove references to blamodule., like so:

I have the following directory structure:

blamodule
|-- __init__.py
|-- backends
|   |-- Bla.py
|   `-- __init__.py
`-- call_command.py

With the following contents:

  • blamodule/__init__.py
from . import call_command
from . import backends
  • blamodule/backends/__init__.py
from .Bla import Bla
  • blamodule/backends/Bla.py
from .. import *
from typing import Iterable

class Bla:
    def __init__(self, path: str) -> None:
        self.path = path

    def method(self, options: Iterable[str]) -> str:
        return call_command.call(["BLA"])
  • blamodule/call_command.py
import io

def call() -> str:

    output_buffer = io.StringIO()

    return output_buffer.getvalue()

I crash mypy with the following backtrace:

Traceback (most recent call last):
  File "/path/py3env/bin/mypy", line 11, in <module>
    sys.exit(console_entry())
  File "/path/py3env/lib/python3.5/site-packages/mypy/__main__.py", line 7, in console_entry
    main(None)
  File "/path/py3env/lib/python3.5/site-packages/mypy/main.py", line 50, in main
    res = type_check_only(sources, bin_dir, options)
  File "/path/py3env/lib/python3.5/site-packages/mypy/main.py", line 103, in type_check_only
    options=options)
  File "/path/py3env/lib/python3.5/site-packages/mypy/build.py", line 198, in build
    graph = dispatch(sources, manager)
  File "/path/py3env/lib/python3.5/site-packages/mypy/build.py", line 1833, in dispatch
    graph = load_graph(sources, manager)
  File "/path/py3env/lib/python3.5/site-packages/mypy/build.py", line 1946, in load_graph
    caller_state=st, caller_line=st.dep_line_map.get(dep, 1))
  File "/path/py3env/lib/python3.5/site-packages/mypy/build.py", line 1466, in __init__
    self.parse_file()
  File "/path/py3env/lib/python3.5/site-packages/mypy/build.py", line 1663, in parse_file
    self.ignore_all or self.options.ignore_errors)
  File "/usr/lib/python3.5/contextlib.py", line 77, in __exit__
    self.gen.throw(type, value, traceback)
  File "/path/py3env/lib/python3.5/site-packages/mypy/build.py", line 1554, in wrap_context
    yield
  File "/path/py3env/lib/python3.5/site-packages/mypy/build.py", line 1663, in parse_file
    self.ignore_all or self.options.ignore_errors)
  File "/path/py3env/lib/python3.5/site-packages/mypy/build.py", line 589, in parse_file
    tree = parse(source, path, self.errors, options=self.options)
  File "/path/py3env/lib/python3.5/site-packages/mypy/parse.py", line 25, in parse
    options=options)
  File "/path/py3env/lib/python3.5/site-packages/mypy/fastparse.py", line 96, in parse
    ).visit(ast)
  File "/path/py3env/lib/python3.5/site-packages/mypy/fastparse.py", line 169, in visit
    return super().visit(node)
  File "/path/py3env/lib/python3.5/site-packages/typed_ast/ast3.py", line 275, in visit
    return visitor(node)
  File "/path/py3env/lib/python3.5/site-packages/mypy/fastparse.py", line 289, in visit_Module
    body = self.fix_function_overloads(self.translate_stmt_list(mod.body))
  File "/path/py3env/lib/python3.5/site-packages/mypy/fastparse.py", line 182, in translate_stmt_list
    stmt = self.visit(e)
  File "/path/py3env/lib/python3.5/site-packages/mypy/fastparse.py", line 169, in visit
    return super().visit(node)
  File "/path/py3env/lib/python3.5/site-packages/typed_ast/ast3.py", line 275, in visit
    return visitor(node)
  File "/path/py3env/lib/python3.5/site-packages/mypy/fastparse.py", line 126, in wrapper
    node = f(self, ast)
  File "/path/py3env/lib/python3.5/site-packages/mypy/fastparse.py", line 654, in visit_ImportFrom
    assert n.module is not None
AssertionError: 

@ilevkivskyi
Copy link
Member

Yes, this is actually a regression introduced by me. Fortunately, this one is easy to fix (just replace None with '').

@ilevkivskyi ilevkivskyi self-assigned this Oct 13, 2017
matzipan added a commit to matzipan/mypy that referenced this issue Oct 13, 2017
gvanrossum pushed a commit that referenced this issue Nov 17, 2017
Fixes #4111

This corrects a previous wrong --strict-optional change (and adds various tests).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants