You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
typing_extension.Self infers the wrong type from __new__ #4668
Note: if you are reporting a wrong signature of a function or a class in the standard library, then the typeshed tracker is better suited for this report: https://github.com/python/typeshed/issues.
Describe the bug
When using __new__ directly (example below), the return type is the class itself instead of inferring from the first classmethod param (cls)
typing_extensions is 4.5.0
I narrowed down what in the configs causes it: setting "typeshedPath". In this case, my minimal pyrightconfig.json is as such:
I can confirm I have no typing_extensions-stubs in my env:
Note this happens with typing too: npx pyright@1.1.294 .\scripts\stubsabot.py --pythonversion=3.11
pyright 1.1.294
E:\Users\Avasam\Documents\Git\typeshed\scripts\stubsabot.py
E:\Users\Avasam\Documents\Git\typeshed\scripts\stubsabot.py:8:21 - information: Type of "member" is "int"
E:\Users\Avasam\Documents\Git\typeshed\scripts\stubsabot.py:9:16 - error: Cannot assign member "_value_" for type "int"
Member "_value_" is unknown (reportGeneralTypeIssues)
E:\Users\Avasam\Documents\Git\typeshed\scripts\stubsabot.py:11:16 - error: Expression of type "int" cannot be assigned to return type "Self@ActionLevel"
"int" is incompatible with "ActionLevel" (reportGeneralTypeIssues)
2 errors, 0 warnings, 1 information
Is this something that can be fixed on typeshed's side? Or is it due to some special casing done with "typeshedPath" ?
Ah, you're using a version of typeshed that is newer than what is bundled with pyright 1.1.294. That's an important detail! I'm able to repro the problem now, so I'll investigate further.
Activity
erictraut commentedon Feb 21, 2023
I'm not able to repro the problem you're seeing. Here's the behavior I see:
Can you confirm that when you paste the above code into a new editor window in a new project with default pyright settings that you get an error?
Perhaps you have an old version of
typing_extensionsortyping_extensions-stubsinstalled in your environment?Avasam commentedon Feb 21, 2023
typing_extensionsis 4.5.0I narrowed down what in the configs causes it: setting
"typeshedPath". In this case, my minimalpyrightconfig.jsonis as such:{ "$schema": "https://raw.githubusercontent.com/microsoft/pyright/main/packages/vscode-pyright/schemas/pyrightconfig.schema.json", "typeshedPath": ".", }I can confirm I have no

typing_extensions-stubsin my env:Note this happens with
typingtoo:npx pyright@1.1.294 .\scripts\stubsabot.py --pythonversion=3.11Is this something that can be fixed on typeshed's side? Or is it due to some special casing done with
"typeshedPath"?erictraut commentedon Feb 21, 2023
Ah, you're using a version of typeshed that is newer than what is bundled with pyright 1.1.294. That's an important detail! I'm able to repro the problem now, so I'll investigate further.
Fixed bug that resulted in incorrect type evaluation when a `__new__`…
erictraut commentedon Feb 22, 2023
Thanks for the bug report. This will be addressed in the next release.
erictraut commentedon Feb 22, 2023
This is addressed in pyright 1.1.295, which I just published. It will also be included in a future release of pylance.