Need help annotating class with dynamic inheritance
Open
Nobody has claimed this yet.
bug
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
To Reproduce
Gist URL: https://gist.github.com/mypy-play/d139ee55a5729d2ec5b63d4ceaeb5a33
Playground URL: https://mypy-play.net/?mypy=latest&python=3.12&gist=d139ee55a5729d2ec5b63d4ceaeb5a33
$ python test_mypy.py
header
1
header
2
$ mypy test_mypy.py
Warning: --strict-concatenate is deprecated; use --extra-checks instead
test_mypy.py:27: error: "__new__" must return a class instance (got "BaseClassT") [misc]
test_mypy.py:36: error: Unsupported argument 1 for "super" [misc]
test_mypy.py:38: error: Returning Any from function declared to return "BaseClassT" [no-any-return]
test_mypy.py:41: error: Non-overlapping identity check (left operand type: "type[BaseClassT]", right operand type: "type[Type1]") [comparison-overlap]
test_mypy.py:42: error: Returning Any from function declared to return "None" [no-any-return]
test_mypy.py:42: error: "Example[BaseClassT]" has no attribute "method1"; maybe "method"? [attr-defined]
test_mypy.py:43: error: Non-overlapping identity check (left operand type: "type[BaseClassT]", right operand type: "type[Type2]") [comparison-overlap]
test_mypy.py:44: error: Returning Any from function declared to return "None" [no-any-return]
test_mypy.py:44: error: "Example[BaseClassT]" has no attribute "method2"; maybe "method"? [attr-defined]
test_mypy.py:48: error: Missing type parameters for generic type "Example" [type-arg]
test_mypy.py:54: error: Cannot instantiate abstract class "ExampleSubclass" with abstract attribute "base_class" [abstract]
test_mypy.py:55: error: Cannot instantiate abstract class "ExampleSubclass" with abstract attribute "base_class" [abstract]
Found 12 errors in 1 file (checked 1 source file)
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 with the linked gist or playground, then run the shown python test_mypy.py and mypy test_mypy.py commands to reproduce the diagnostics in test_mypy.py. Trace the reported errors around the dynamically inherited class and compare them with the runtime output. Done means establishing the expected typing behavior and a clear minimal reproduction for any follow-up.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100