Skip to content

Recognise the @object.__new__ decorator on a class definition #12265

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

Open
DanielNoord opened this issue Mar 1, 2022 · 0 comments
Open

Recognise the @object.__new__ decorator on a class definition #12265

DanielNoord opened this issue Mar 1, 2022 · 0 comments

Comments

@DanielNoord
Copy link

Bug Report

For the following code:

@object.__new__
class A:
    ...

class B:
    ...

reveal_type(A)
reveal_type(B)

mypy returns:

test.py:8: note: Revealed type is "def () -> test.A"
test.py:9: note: Revealed type is "def () -> test.B"

If you print instead of reveal_type it shows that:

<__main__.A object at 0x1081cfb50>
<class '__main__.B'>

Following screenshot shows that ``pyright` does recognise this.

Schermafbeelding 2022-03-01 om 10 52 15

Expected Behavior

Recognise that the @object.__new__ decorator turns A into an instance of A and set that as its type.

Actual Behavior

A is now inferred as Type[A].

Your Environment

  • Mypy version used: 0.931
  • Mypy command-line flags: None
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.10
  • Operating system and version: MacOS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants