Bad error message: mypy reports 'Name is not defined' when using an object member as super class of another class
Open
Nobody has claimed this yet.
good-first-issue
priority-2-low
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Consider the following valid Python 3 code:
class A():
pass
class B():
def __init__(self):
self.a = A
b = B()
class C(b.a):
pass
Actual behavior:
Mypy will report Name 'b.a' is not defined on the line class C(b.a):.
Expected behavior:
No error reported by Mypy.
Python version: 3.8.2
Mypy version: 0.770 (master not checked)
Flags: no flags
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the reported Python snippet with mypy and trace how the type checker handles an object member used in a class base expression. The issue is done when this valid code produces no 'Name is not defined' error and a regression test covers the behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100