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

AssertionError: Var is lacking info - access to class variable imported in context class #11641

Closed
ampanasiuk opened this issue Nov 29, 2021 · 3 comments · Fixed by #12023
Closed
Labels

Comments

@ampanasiuk
Copy link

ampanasiuk commented Nov 29, 2021

Crash Report

# user.py
name = 'Bob'

# hello.py
class Hello:
    from user import name

    def greet(self) -> None:
          print(self.name)

Traceback

mypy/nodes.py:2705 (__getattribute__) is the deepest frame

To Reproduce

$ mypy hello.py

Your Environment

  • Mypy version used: 0.910
  • Mypy command-line flags: filename
  • Mypy configuration options from mypy.ini (and other config files): no
  • Python version used: 3.8.12
  • Operating system and version: cygwin

Thanks for looking into this,

@ampanasiuk
Copy link
Author

For anyone inconvenienced with this issue, this is how to work around it:

# user.py
from typing import TYPE_CHECKING

if TYPE_CHECKING:
    class name:
        pass
else:
    name = 'Bob'

@hauntsaninja
Copy link
Collaborator

Thanks, similar to #7806

Reproes on master, full traceback:

version: 0.920+dev.4f59ca490072a45dce5839e6397791d79dcf3352
Traceback (most recent call last):
  File "/Users/shantanu/.virtualenvs/mypy-fpoc/bin/mypy", line 33, in <module>
    sys.exit(load_entry_point('mypy', 'console_scripts', 'mypy')())
  File "/Users/shantanu/dev/mypy/mypy/__main__.py", line 12, in console_entry
    main(None, sys.stdout, sys.stderr)
  File "/Users/shantanu/dev/mypy/mypy/main.py", line 96, in main
    res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
  File "/Users/shantanu/dev/mypy/mypy/main.py", line 173, in run_build
    res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
  File "/Users/shantanu/dev/mypy/mypy/build.py", line 180, in build
    result = _build(
  File "/Users/shantanu/dev/mypy/mypy/build.py", line 256, in _build
    graph = dispatch(sources, manager, stdout)
  File "/Users/shantanu/dev/mypy/mypy/build.py", line 2715, in dispatch
    process_graph(graph, manager)
  File "/Users/shantanu/dev/mypy/mypy/build.py", line 3046, in process_graph
    process_stale_scc(graph, scc, manager)
  File "/Users/shantanu/dev/mypy/mypy/build.py", line 3144, in process_stale_scc
    graph[id].type_check_first_pass()
  File "/Users/shantanu/dev/mypy/mypy/build.py", line 2180, in type_check_first_pass
    self.type_checker().check_first_pass()
  File "/Users/shantanu/dev/mypy/mypy/checker.py", line 317, in check_first_pass
    self.accept(d)
  File "/Users/shantanu/dev/mypy/mypy/checker.py", line 423, in accept
    stmt.accept(self)
  File "/Users/shantanu/dev/mypy/mypy/nodes.py", line 1000, in accept
    return visitor.visit_class_def(self)
  File "/Users/shantanu/dev/mypy/mypy/checker.py", line 1778, in visit_class_def
    self.accept(defn.defs)
  File "/Users/shantanu/dev/mypy/mypy/checker.py", line 423, in accept
    stmt.accept(self)
  File "/Users/shantanu/dev/mypy/mypy/nodes.py", line 1069, in accept
    return visitor.visit_block(self)
  File "/Users/shantanu/dev/mypy/mypy/checker.py", line 2040, in visit_block
    self.accept(s)
  File "/Users/shantanu/dev/mypy/mypy/checker.py", line 423, in accept
    stmt.accept(self)
  File "/Users/shantanu/dev/mypy/mypy/nodes.py", line 727, in accept
    return visitor.visit_func_def(self)
  File "/Users/shantanu/dev/mypy/mypy/checker.py", line 763, in visit_func_def
    self._visit_func_def(defn)
  File "/Users/shantanu/dev/mypy/mypy/checker.py", line 767, in _visit_func_def
    self.check_func_item(defn, name=defn.name)
  File "/Users/shantanu/dev/mypy/mypy/checker.py", line 829, in check_func_item
    self.check_func_def(defn, typ, name)
  File "/Users/shantanu/dev/mypy/mypy/checker.py", line 1014, in check_func_def
    self.accept(item.body)
  File "/Users/shantanu/dev/mypy/mypy/checker.py", line 423, in accept
    stmt.accept(self)
  File "/Users/shantanu/dev/mypy/mypy/nodes.py", line 1069, in accept
    return visitor.visit_block(self)
  File "/Users/shantanu/dev/mypy/mypy/checker.py", line 2040, in visit_block
    self.accept(s)
  File "/Users/shantanu/dev/mypy/mypy/checker.py", line 423, in accept
    stmt.accept(self)
  File "/Users/shantanu/dev/mypy/mypy/nodes.py", line 1087, in accept
    return visitor.visit_expression_stmt(self)
  File "/Users/shantanu/dev/mypy/mypy/checker.py", line 3316, in visit_expression_stmt
    self.expr_checker.accept(s.expr, allow_none_return=True, always_allow_any=True)
  File "/Users/shantanu/dev/mypy/mypy/checkexpr.py", line 3966, in accept
    typ = self.visit_call_expr(node, allow_none_return=True)
  File "/Users/shantanu/dev/mypy/mypy/checkexpr.py", line 288, in visit_call_expr
    return self.visit_call_expr_inner(e, allow_none_return=allow_none_return)
  File "/Users/shantanu/dev/mypy/mypy/checkexpr.py", line 377, in visit_call_expr_inner
    ret_type = self.check_call_expr_with_callee_type(callee_type, e, fullname,
  File "/Users/shantanu/dev/mypy/mypy/checkexpr.py", line 884, in check_call_expr_with_callee_type
    return self.check_call(callee_type, e.args, e.arg_kinds, e,
  File "/Users/shantanu/dev/mypy/mypy/checkexpr.py", line 948, in check_call
    return self.check_overload_call(callee, args, arg_kinds, arg_names, callable_name,
  File "/Users/shantanu/dev/mypy/mypy/checkexpr.py", line 1589, in check_overload_call
    arg_types = self.infer_arg_types_in_empty_context(args)
  File "/Users/shantanu/dev/mypy/mypy/checkexpr.py", line 1132, in infer_arg_types_in_empty_context
    arg_type = self.accept(arg)
  File "/Users/shantanu/dev/mypy/mypy/checkexpr.py", line 3972, in accept
    typ = node.accept(self)
  File "/Users/shantanu/dev/mypy/mypy/nodes.py", line 1631, in accept
    return visitor.visit_member_expr(self)
  File "/Users/shantanu/dev/mypy/mypy/checkexpr.py", line 2086, in visit_member_expr
    result = self.analyze_ordinary_member_access(e, is_lvalue)
  File "/Users/shantanu/dev/mypy/mypy/checkexpr.py", line 2104, in analyze_ordinary_member_access
    member_type = analyze_member_access(
  File "/Users/shantanu/dev/mypy/mypy/checkmember.py", line 126, in analyze_member_access
    result = _analyze_member_access(name, typ, mx, override_info)
  File "/Users/shantanu/dev/mypy/mypy/checkmember.py", line 143, in _analyze_member_access
    return analyze_instance_member_access(name, typ, mx, override_info)
  File "/Users/shantanu/dev/mypy/mypy/checkmember.py", line 227, in analyze_instance_member_access
    return analyze_member_var_access(name, typ, info, mx)
  File "/Users/shantanu/dev/mypy/mypy/checkmember.py", line 382, in analyze_member_var_access
    return analyze_var(name, v, itype, info, mx, implicit=implicit)
  File "/Users/shantanu/dev/mypy/mypy/checkmember.py", line 555, in analyze_var
    itype = map_instance_to_supertype(itype, var.info)
  File "/Users/shantanu/dev/mypy/mypy/maptype.py", line 20, in map_instance_to_supertype
    if not superclass.type_vars:
  File "/Users/shantanu/dev/mypy/mypy/nodes.py", line 2876, in __getattribute__
    raise AssertionError(object.__getattribute__(self, 'msg'))
AssertionError: Var is lacking info

@sobolevn
Copy link
Member

sobolevn commented Dec 2, 2021

This might be fixed by: #11344

hauntsaninja pushed a commit to hauntsaninja/mypy that referenced this issue Jan 20, 2022
JelleZijlstra pushed a commit that referenced this issue Feb 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants