-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Use typing_extensions.Self
in the stdlib
#9694
Conversation
This comment has been minimized.
This comment has been minimized.
Diff from mypy_primer, showing the effect of this PR on open source code: mongo-python-driver (https://github.com/mongodb/mongo-python-driver)
+ bson/son.py: note: In member "__new__" of class "SON":
+ bson/son.py:69: error: Value of type variable "Self" of "__new__" of "dict" cannot be "SON[_Key, _Value]" [type-var]
prefect (https://github.com/PrefectHQ/prefect)
- src/prefect/utilities/pydantic.py:161: note: def [Self] __new__(cls: Type[Self], str, Tuple[type, ...], Dict[str, Any], /, **kwds: Any) -> Self
+ src/prefect/utilities/pydantic.py:161: note: def [_typeshed.Self] __new__(cls: Type[_typeshed.Self], str, Tuple[type, ...], Dict[str, Any], /, **kwds: Any) -> _typeshed.Self
- src/prefect/utilities/pydantic.py:163: note: def [Self] __new__(cls: Type[Self], str, Tuple[type, ...], Dict[str, Any], /, **kwds: Any) -> Self
+ src/prefect/utilities/pydantic.py:163: note: def [_typeshed.Self] __new__(cls: Type[_typeshed.Self], str, Tuple[type, ...], Dict[str, Any], /, **kwds: Any) -> _typeshed.Self
steam.py (https://github.com/Gobot1234/steam.py)
- steam/chat.py:401: note: def [Self] __new__(cls: Type[Self], str, Tuple[type, ...], Dict[str, Any], /, **kwds: Any) -> Self
+ steam/chat.py:401: note: def [_typeshed.Self] __new__(cls: Type[_typeshed.Self], str, Tuple[type, ...], Dict[str, Any], /, **kwds: Any) -> _typeshed.Self
|
Not sure what's going on in this one (source here), but it looks like a minor mypy bug in its handling of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The primer hit is probably due to dict.__new__
now being incompatible with the bson type annotation. I'm fine with that.
It's weird that |
@@ -196,9 +198,9 @@ _LiteralInteger = _PositiveInteger | _NegativeInteger | Literal[0] # noqa: Y026 | |||
|
|||
class int: | |||
@overload | |||
def __new__(cls: type[Self], __x: str | ReadableBuffer | SupportsInt | SupportsIndex | SupportsTrunc = ...) -> Self: ... | |||
def __new__(cls, __x: str | ReadableBuffer | SupportsInt | SupportsIndex | SupportsTrunc = ...) -> Self: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed this change has introduced a new pyright issue at https://github.com/python/typeshed/blob/main/scripts/stubsabot.py#L37
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My guess is that's probably a pyright issue in how it handles Self
. What's the error message pyright produces?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, yeah that seems like it might be a pyright bug (though Eric will be the judge of that). If you file an issue over there, he'll probably either fix it or triage it as "wontfix" within 24 hours :D
We also don't need the ActionLevelSelf
TypeVar
in stubsabot anymore, though, we can just use typing_extensions.Self
there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also don't need the
ActionLevelSelf
TypeVar
in stubsabot anymore, though, we can just usetyping_extensions.Self
there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, created an issue here: microsoft/pyright#4668
Coming here because I'm attempting to fix or # type: ignore the SON error (in mongodb/mongo-python-driver#1194).
Has an issue been created for this yet? It's not clear to me whether this is a bug in pymongo or a bug in mypy. |
It looks like a mypy bug to me. The |
Thanks I opened: python/mypy#15135 |
Only doing the stdlib for now, so that we don't have a repeat of #9690.
The first commit in this PR was prepared using the following script, which uses
libcst
:Cf. #6300