Skip to content
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

Mypy thinks that class statement always produces some class #13609

Open
denballakh opened this issue Sep 4, 2022 · 1 comment
Open

Mypy thinks that class statement always produces some class #13609

denballakh opened this issue Sep 4, 2022 · 1 comment
Labels
bug mypy got something wrong

Comments

@denballakh
Copy link
Contributor

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 Any and Any

Actual Behavior

  • no errors
  • revealed type X and def (...) -> 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
@denballakh denballakh added the bug mypy got something wrong label Sep 4, 2022
@sobolevn
Copy link
Member

sobolevn commented Sep 5, 2022

The same is true for:

  • Classs decorators that return something else
  • Custom metaclasses that return something else
  • Probably other magic :)

But, yes, this is a limitation we have for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

2 participants