Mypy thinks that `class` statement always produces some class
Open
Nobody has claimed this yet.
bug
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
from typing import Any
s: Any = slice(1, 2, 3)
class X(s): ...
print(X) # slice('X', (slice(1, 2, 3),), {'__module__': '__main__', '__qualname__': 'X'})
x = X() # TypeError: 'slice' object is not callable
reveal_type(x) # test.X
reveal_type(X) # def (*_args: Any, **_kwds: Any) -> test.X
At runtime X is not a class, it is instance of slice, but mypy thinks that class statement always produces some class.
Expected Behavior
- no errors
- revealed types
AnyandAny
Actual Behavior
- no errors
- revealed type
Xanddef (...) -> X, what is wrong
Your Environment
- Mypy version used:
mypy 0.971 (compiled: yes) - Mypy command-line flags: none
- Mypy configuration options from
mypy.ini(and other config files): none - Python version used: 3.10.6
- Operating system and version: Win10
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 minimal example in the issue and reproduce its reveal_type output using mypy. Trace the class-statement analysis and handling of the dynamic base expression; done means the example reports Any for both x and X while preserving the no-errors result.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100