Recognise the ``@object.__new__`` decorator on a class definition
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
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.
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
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 by reproducing the example in test.py with mypy and compare the reveal_type results with the expected runtime behavior. Trace the existing handling of decorators applied to class definitions; done means @object.new makes A infer as an instance of A while B remains a class.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100