From 366f417452bd7f34f1a7222b3b4fd28ce1389ad9 Mon Sep 17 00:00:00 2001 From: jorenham Date: Thu, 29 May 2025 04:33:00 +0200 Subject: [PATCH 1/3] add `types.MethodType.__get__` --- stdlib/types.pyi | 1 + 1 file changed, 1 insertion(+) diff --git a/stdlib/types.pyi b/stdlib/types.pyi index 8bb07d166d38..6a3f33c5b08e 100644 --- a/stdlib/types.pyi +++ b/stdlib/types.pyi @@ -482,6 +482,7 @@ class MethodType: def __qualname__(self) -> str: ... # inherited from the added function def __new__(cls, func: Callable[..., Any], instance: object, /) -> Self: ... def __call__(self, *args: Any, **kwargs: Any) -> Any: ... + def __get__(self, instance: object, owner: type | None = None, /) -> Self: ... def __eq__(self, value: object, /) -> bool: ... def __hash__(self) -> int: ... From 256096f1b2132359176abc98e396f11b09afb922 Mon Sep 17 00:00:00 2001 From: jorenham Date: Thu, 29 May 2025 04:38:37 +0200 Subject: [PATCH 2/3] limit `types.MethodType.__get__` to `python>=3.13` --- stdlib/types.pyi | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/stdlib/types.pyi b/stdlib/types.pyi index 6a3f33c5b08e..283c26142237 100644 --- a/stdlib/types.pyi +++ b/stdlib/types.pyi @@ -101,6 +101,7 @@ class FunctionType: closure: tuple[CellType, ...] | None = None, kwdefaults: dict[str, object] | None = None, ) -> Self: ... + else: def __new__( cls, @@ -153,6 +154,7 @@ class CodeType: @property @deprecated("Will be removed in Python 3.15. Use the co_lines() method instead.") def co_lnotab(self) -> bytes: ... + else: @property def co_lnotab(self) -> bytes: ... @@ -197,6 +199,7 @@ class CodeType: cellvars: tuple[str, ...] = ..., /, ) -> Self: ... + elif sys.version_info >= (3, 10): def __new__( cls, @@ -218,6 +221,7 @@ class CodeType: cellvars: tuple[str, ...] = ..., /, ) -> Self: ... + else: def __new__( cls, @@ -262,6 +266,7 @@ class CodeType: co_linetable: bytes = ..., co_exceptiontable: bytes = ..., ) -> Self: ... + elif sys.version_info >= (3, 10): def replace( self, @@ -283,6 +288,7 @@ class CodeType: co_name: str = ..., co_linetable: bytes = ..., ) -> Self: ... + else: def replace( self, @@ -333,6 +339,7 @@ class SimpleNamespace: __hash__: ClassVar[None] # type: ignore[assignment] if sys.version_info >= (3, 13): def __init__(self, mapping_or_iterable: Mapping[str, Any] | Iterable[tuple[str, Any]] = (), /, **kwargs: Any) -> None: ... + else: def __init__(self, **kwargs: Any) -> None: ... @@ -482,7 +489,10 @@ class MethodType: def __qualname__(self) -> str: ... # inherited from the added function def __new__(cls, func: Callable[..., Any], instance: object, /) -> Self: ... def __call__(self, *args: Any, **kwargs: Any) -> Any: ... - def __get__(self, instance: object, owner: type | None = None, /) -> Self: ... + + if sys.version_info >= (3, 13): + def __get__(self, instance: object, owner: type | None = None, /) -> Self: ... + def __eq__(self, value: object, /) -> bool: ... def __hash__(self) -> int: ... From bdbd4048306b7ac0e5f219f81e58af12f02a9568 Mon Sep 17 00:00:00 2001 From: Joren Hammudoglu Date: Fri, 30 May 2025 17:26:15 +0200 Subject: [PATCH 3/3] revert newlines inserted by ruff autoformat --- stdlib/types.pyi | 7 ------- 1 file changed, 7 deletions(-) diff --git a/stdlib/types.pyi b/stdlib/types.pyi index 283c26142237..d9f8e8756833 100644 --- a/stdlib/types.pyi +++ b/stdlib/types.pyi @@ -101,7 +101,6 @@ class FunctionType: closure: tuple[CellType, ...] | None = None, kwdefaults: dict[str, object] | None = None, ) -> Self: ... - else: def __new__( cls, @@ -154,7 +153,6 @@ class CodeType: @property @deprecated("Will be removed in Python 3.15. Use the co_lines() method instead.") def co_lnotab(self) -> bytes: ... - else: @property def co_lnotab(self) -> bytes: ... @@ -199,7 +197,6 @@ class CodeType: cellvars: tuple[str, ...] = ..., /, ) -> Self: ... - elif sys.version_info >= (3, 10): def __new__( cls, @@ -221,7 +218,6 @@ class CodeType: cellvars: tuple[str, ...] = ..., /, ) -> Self: ... - else: def __new__( cls, @@ -266,7 +262,6 @@ class CodeType: co_linetable: bytes = ..., co_exceptiontable: bytes = ..., ) -> Self: ... - elif sys.version_info >= (3, 10): def replace( self, @@ -288,7 +283,6 @@ class CodeType: co_name: str = ..., co_linetable: bytes = ..., ) -> Self: ... - else: def replace( self, @@ -339,7 +333,6 @@ class SimpleNamespace: __hash__: ClassVar[None] # type: ignore[assignment] if sys.version_info >= (3, 13): def __init__(self, mapping_or_iterable: Mapping[str, Any] | Iterable[tuple[str, Any]] = (), /, **kwargs: Any) -> None: ... - else: def __init__(self, **kwargs: Any) -> None: ...