Inconsistency with NewType
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
Research direction
Start by reproducing the supplied NewType example and compare mypy's accepted operations with Python's runtime behavior. Trace the existing NewType handling and determine the intended boundary between calling a NewType and using it in an annotation; the issue needs a precise completion criterion and related tests before implementation can begin.
Written by the indexing model from the issue text.
Description
This passes a type check:
from typing import NewType
class C:
@classmethod
def foo(cls) -> int: pass
D = NewType('D', C)
D.foo() # Runtime error here (line 5)
But it fails at runtime, like this:
Traceback (most recent call last):
File "_.py", line 6, in <module>
D.foo()
AttributeError: 'function' object has no attribute 'foo'
This is because at runtime D is just a function (the identity function, to be clear) but mypy type-checks the program assuming it is a subclass of C.
Perhaps we can keep track of the status of D as a NewType and ensure that nothing is done to it except calling it (or using it in an annotation)?
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 54
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.
More from python/mypy
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
bug topic-configuration topic-error-reporting
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
zostera/django-bootstrap4#894 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
use-agent-os/agent-os#3276 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
zephyrproject-rtos/zephyr#119726 ·
-
area/auth bug comp/agent P3 platform/discord type/security
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
NousResearch/hermes-agent#117848 ·