Skip to content

Crash on type: ignore in import #1327

Closed
@drewhaven

Description

@drewhaven

We have some code to the effect of

if IS_LINUX:
    from linux_class import SomeClass
elif IS_MAC:
    from mac_class import SomeClass
elif IS_WINDOWS:
    from windows_class import SomeClass

assert SomeClass

Because SomeClass doesn't have quite the same interface in all three places, I tried to add type: ignore to the second and third imports. This caused the following crash while running mypy:

  File "/code/client-all/client/.mypy_lint/mypy/mypy/main.py", line 51, in main
    type_check_only(sources, bin_dir, options)
  File "/code/client-all/client/.mypy_lint/mypy/mypy/main.py", line 95, in type_check_only
    python_path=options.python_path)
  File "/code/client-all/client/.mypy_lint/mypy/mypy/build.py", line 239, in build
    result = manager.process(initial_states)
  File "/code/client-all/client/.mypy_lint/mypy/mypy/build.py", line 456, in process
    next.process()
  File "/code/client-all/client/.mypy_lint/mypy/mypy/build.py", line 964, in process
    self.type_checker().visit_file(self.tree, self.tree.path)
  File "/code/client-all/client/.mypy_lint/mypy/mypy/checker.py", line 416, in visit_file
    self.accept(d)
  File "/code/client-all/client/.mypy_lint/mypy/mypy/checker.py", line 457, in accept
    typ = node.accept(self)
  File "/code/client-all/client/.mypy_lint/mypy/mypy/nodes.py", line 632, in accept
    return visitor.visit_assert_stmt(self)
  File "/code/client-all/client/.mypy_lint/mypy/mypy/checker.py", line 1710, in visit_assert_stmt
    self.accept(s.expr)
  File "/code/client-all/client/.mypy_lint/mypy/mypy/checker.py", line 457, in accept
    typ = node.accept(self)
  File "/code/client-all/client/.mypy_lint/mypy/mypy/nodes.py", line 902, in accept
    return visitor.visit_name_expr(self)
  File "/code/client-all/client/.mypy_lint/mypy/mypy/checker.py", line 1961, in visit_name_expr
    return self.expr_checker.visit_name_expr(e)
  File "/code/client-all/client/.mypy_lint/mypy/mypy/checkexpr.py", line 75, in visit_name_expr
    result = self.analyze_ref_expr(e)
  File "/code/client-all/client/.mypy_lint/mypy/mypy/checkexpr.py", line 103, in analyze_ref_expr
    result = type_object_type(node, self.named_type)
  File "/code/client-all/client/.mypy_lint/mypy/mypy/checkmember.py", line 320, in type_object_type
    init_method = info.get_method('__init__')
  File "/code/client-all/client/.mypy_lint/mypy/mypy/nodes.py", line 1593, in get_method
    for cls in self.mro:
TypeError: 'NoneType' object is not iterable

I've spent some time trying to get a small example of how to repro this, but haven't been able to yet.

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