Skip to content

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

Open
@DanielNoord

Description

@DanielNoord

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions