"Invalid base class" raised when Base Class is a class field
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
Research direction
Start by running the provided reproducer with mypy and compare how the module-level Base and Types.Base are resolved when used as class bases. Trace the type-checking path for class fields and base-class validation. Done means the reproducer accepts Fails(Types.Base) without the invalid-type or invalid-base-class errors while preserving the existing reveal types.
Written by the indexing model from the issue text.
Description
Repro:
class Foo:
pass
Base = Foo
class Types:
Base = Foo
reveal_type(Base)
reveal_type(Types.Base)
class Works(Base):
pass
class Fails(Types.Base):
pass
Results in:
test_cast.py:9: error: Revealed type is 'def () -> test_cast.Foo'
test_cast.py:10: error: Revealed type is 'def () -> test_cast.Foo'
test_cast.py:15: error: Invalid type "Base"
test_cast.py:15: error: Invalid base class
What's odd is that mypy recognizes Base and Types.Base as having identical types yet accepts Base as a base class but not Types.Base
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 54
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.
More from python/mypy
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
bug topic-configuration topic-error-reporting
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
bancolombia/sentinel#23 ·
-
test md OpenCI
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
bug client
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100