-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Mypy fails on some type hints #8891
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
Comments
There's nothing obviously wrong in the code you posted. Maybe another team member is able to figure out from the stack trace what the issue is. If you can minimize this to a self-contained example, that could also help. |
Could you try an install of mypy from git? https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build |
I tested it with mypy from master and it seems to crash at another place: tracebackversion: 0.770+dev.f94fc7e251330f7e3668aea1f062cdbae1ed7232
Traceback (most recent call last):
File "/home/chris/.cache/pypoetry/virtualenvs/nqontrol-8ry3BIFW-py3.8/bin/mypy", line 10, in <module>
sys.exit(console_entry())
File "/home/chris/.cache/pypoetry/virtualenvs/nqontrol-8ry3BIFW-py3.8/lib64/python3.8/site-packages/mypy/__main__.py", line 8, in console_entry
main(None, sys.stdout, sys.stderr)
File "/home/chris/.cache/pypoetry/virtualenvs/nqontrol-8ry3BIFW-py3.8/lib64/python3.8/site-packages/mypy/main.py", line 89, in main
res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
File "/home/chris/.cache/pypoetry/virtualenvs/nqontrol-8ry3BIFW-py3.8/lib64/python3.8/site-packages/mypy/build.py", line 180, in build
result = _build(
File "/home/chris/.cache/pypoetry/virtualenvs/nqontrol-8ry3BIFW-py3.8/lib64/python3.8/site-packages/mypy/build.py", line 252, in _build
graph = dispatch(sources, manager, stdout)
File "/home/chris/.cache/pypoetry/virtualenvs/nqontrol-8ry3BIFW-py3.8/lib64/python3.8/site-packages/mypy/build.py", line 2626, in dispatch
process_graph(graph, manager)
File "/home/chris/.cache/pypoetry/virtualenvs/nqontrol-8ry3BIFW-py3.8/lib64/python3.8/site-packages/mypy/build.py", line 2949, in process_graph
process_stale_scc(graph, scc, manager)
File "/home/chris/.cache/pypoetry/virtualenvs/nqontrol-8ry3BIFW-py3.8/lib64/python3.8/site-packages/mypy/build.py", line 3047, in process_stale_scc
graph[id].type_check_first_pass()
File "/home/chris/.cache/pypoetry/virtualenvs/nqontrol-8ry3BIFW-py3.8/lib64/python3.8/site-packages/mypy/build.py", line 2107, in type_check_first_pass
self.type_checker().check_first_pass()
File "/home/chris/.cache/pypoetry/virtualenvs/nqontrol-8ry3BIFW-py3.8/lib64/python3.8/site-packages/mypy/checker.py", line 294, in check_first_pass
self.accept(d)
File "/home/chris/.cache/pypoetry/virtualenvs/nqontrol-8ry3BIFW-py3.8/lib64/python3.8/site-packages/mypy/checker.py", line 401, in accept
stmt.accept(self)
File "/home/chris/.cache/pypoetry/virtualenvs/nqontrol-8ry3BIFW-py3.8/lib64/python3.8/site-packages/mypy/nodes.py", line 676, in accept
return visitor.visit_func_def(self)
File "/home/chris/.cache/pypoetry/virtualenvs/nqontrol-8ry3BIFW-py3.8/lib64/python3.8/site-packages/mypy/checker.py", line 726, in visit_func_def
self._visit_func_def(defn)
File "/home/chris/.cache/pypoetry/virtualenvs/nqontrol-8ry3BIFW-py3.8/lib64/python3.8/site-packages/mypy/checker.py", line 730, in _visit_func_def
self.check_func_item(defn, name=defn.name)
File "/home/chris/.cache/pypoetry/virtualenvs/nqontrol-8ry3BIFW-py3.8/lib64/python3.8/site-packages/mypy/checker.py", line 792, in check_func_item
self.check_func_def(defn, typ, name)
File "/home/chris/.cache/pypoetry/virtualenvs/nqontrol-8ry3BIFW-py3.8/lib64/python3.8/site-packages/mypy/checker.py", line 975, in check_func_def
self.accept(item.body)
File "/home/chris/.cache/pypoetry/virtualenvs/nqontrol-8ry3BIFW-py3.8/lib64/python3.8/site-packages/mypy/checker.py", line 401, in accept
stmt.accept(self)
File "/home/chris/.cache/pypoetry/virtualenvs/nqontrol-8ry3BIFW-py3.8/lib64/python3.8/site-packages/mypy/nodes.py", line 1004, in accept
return visitor.visit_block(self)
File "/home/chris/.cache/pypoetry/virtualenvs/nqontrol-8ry3BIFW-py3.8/lib64/python3.8/site-packages/mypy/checker.py", line 1973, in visit_block
self.accept(s)
File "/home/chris/.cache/pypoetry/virtualenvs/nqontrol-8ry3BIFW-py3.8/lib64/python3.8/site-packages/mypy/checker.py", line 401, in accept
stmt.accept(self)
File "/home/chris/.cache/pypoetry/virtualenvs/nqontrol-8ry3BIFW-py3.8/lib64/python3.8/site-packages/mypy/nodes.py", line 1062, in accept
return visitor.visit_assignment_stmt(self)
File "/home/chris/.cache/pypoetry/virtualenvs/nqontrol-8ry3BIFW-py3.8/lib64/python3.8/site-packages/mypy/checker.py", line 2011, in visit_assignment_stmt
self.check_assignment(s.lvalues[-1], s.rvalue, s.type is None, s.new_syntax)
File "/home/chris/.cache/pypoetry/virtualenvs/nqontrol-8ry3BIFW-py3.8/lib64/python3.8/site-packages/mypy/checker.py", line 2147, in check_assignment
rvalue_type = self.expr_checker.accept(rvalue)
File "/home/chris/.cache/pypoetry/virtualenvs/nqontrol-8ry3BIFW-py3.8/lib64/python3.8/site-packages/mypy/checkexpr.py", line 3757, in accept
typ = node.accept(self)
File "/home/chris/.cache/pypoetry/virtualenvs/nqontrol-8ry3BIFW-py3.8/lib64/python3.8/site-packages/mypy/nodes.py", line 1544, in accept
return visitor.visit_call_expr(self)
File "/home/chris/.cache/pypoetry/virtualenvs/nqontrol-8ry3BIFW-py3.8/lib64/python3.8/site-packages/mypy/checkexpr.py", line 263, in visit_call_expr
return self.visit_call_expr_inner(e, allow_none_return=allow_none_return)
File "/home/chris/.cache/pypoetry/virtualenvs/nqontrol-8ry3BIFW-py3.8/lib64/python3.8/site-packages/mypy/checkexpr.py", line 312, in visit_call_expr_inner
callee_type = get_proper_type(self.accept(e.callee, type_context, always_allow_any=True))
File "/home/chris/.cache/pypoetry/virtualenvs/nqontrol-8ry3BIFW-py3.8/lib64/python3.8/site-packages/mypy/checkexpr.py", line 3757, in accept
typ = node.accept(self)
File "/home/chris/.cache/pypoetry/virtualenvs/nqontrol-8ry3BIFW-py3.8/lib64/python3.8/site-packages/mypy/nodes.py", line 1496, in accept
return visitor.visit_member_expr(self)
File "/home/chris/.cache/pypoetry/virtualenvs/nqontrol-8ry3BIFW-py3.8/lib64/python3.8/site-packages/mypy/checkexpr.py", line 1990, in visit_member_expr
result = self.analyze_ordinary_member_access(e, is_lvalue)
File "/home/chris/.cache/pypoetry/virtualenvs/nqontrol-8ry3BIFW-py3.8/lib64/python3.8/site-packages/mypy/checkexpr.py", line 2008, in analyze_ordinary_member_access
member_type = analyze_member_access(
File "/home/chris/.cache/pypoetry/virtualenvs/nqontrol-8ry3BIFW-py3.8/lib64/python3.8/site-packages/mypy/checkmember.py", line 126, in analyze_member_access
result = _analyze_member_access(name, typ, mx, override_info)
File "/home/chris/.cache/pypoetry/virtualenvs/nqontrol-8ry3BIFW-py3.8/lib64/python3.8/site-packages/mypy/checkmember.py", line 143, in _analyze_member_access
return analyze_instance_member_access(name, typ, mx, override_info)
File "/home/chris/.cache/pypoetry/virtualenvs/nqontrol-8ry3BIFW-py3.8/lib64/python3.8/site-packages/mypy/checkmember.py", line 219, in analyze_instance_member_access
typ = map_instance_to_supertype(typ, method.info)
File "/home/chris/.cache/pypoetry/virtualenvs/nqontrol-8ry3BIFW-py3.8/lib64/python3.8/site-packages/mypy/maptype.py", line 20, in map_instance_to_supertype
if not superclass.type_vars:
File "/home/chris/.cache/pypoetry/virtualenvs/nqontrol-8ry3BIFW-py3.8/lib64/python3.8/site-packages/mypy/nodes.py", line 2659, in __getattribute__
raise AssertionError(object.__getattribute__(self, 'msg'))
AssertionError: FuncBase for non-methods lack info
nqontrol/gui/widgets/servo_section/_callbacks.py:231: : note: use --pdb to drop into pdb Now the line that causes the exception is: def callLockRelock(value: bool, servoNumber: int):
→ servo = DEVICE.servo(servoNumber) EDIT: |
@cddf, is there a repo with the source we could look at? If not, could you describe how |
@ethanhs Yes, I pushed it to our public repo: |
We fixed issues that could lead to that stacktrace. Try again with mypy 0.980 |
I do not know why or how, but, e.g. this piece of code is completely fine:
I is kind of the top level class that uses the next one I'm gonna show, where mypy seems to fail, which is:
Mypy says it fails on the line where i pointed the arrow. The initial error is:
And if I show the traceback
Either I misunderstand the use of type hinting completely (might actually be the case) or it is a bug and very frustrating. :/ Either way I would really appreciate help. 😢
The text was updated successfully, but these errors were encountered: