Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c5b5dd4

Browse files
Various stdlib dunders: correct parameter names; improve types; add defaults (#9761)
Co-authored-by: Jelle Zijlstra <[email protected]>
1 parent 74112dc commit c5b5dd4

8 files changed

Lines changed: 31 additions & 23 deletions

File tree

stdlib/_decimal.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class Decimal:
8989
def __mul__(self, __other: _Decimal) -> Decimal: ...
9090
def __neg__(self) -> Decimal: ...
9191
def __pos__(self) -> Decimal: ...
92-
def __pow__(self, __other: _Decimal, __modulo: _Decimal | None = ...) -> Decimal: ...
92+
def __pow__(self, __value: _Decimal, __mod: _Decimal | None = None) -> Decimal: ...
9393
def __radd__(self, __other: _Decimal) -> Decimal: ...
9494
def __rdivmod__(self, __other: _Decimal) -> tuple[Decimal, Decimal]: ...
9595
def __rfloordiv__(self, __other: _Decimal) -> Decimal: ...
@@ -116,7 +116,7 @@ class Decimal:
116116
def __floor__(self) -> int: ...
117117
def __ceil__(self) -> int: ...
118118
def fma(self, other: _Decimal, third: _Decimal, context: Context | None = None) -> Decimal: ...
119-
def __rpow__(self, __other: _Decimal, __context: Context | None = ...) -> Decimal: ...
119+
def __rpow__(self, __value: _Decimal, __mod: Context | None = None) -> Decimal: ...
120120
def normalize(self, context: Context | None = None) -> Decimal: ...
121121
def quantize(self, exp: _Decimal, rounding: str | None = None, context: Context | None = None) -> Decimal: ...
122122
def same_quantum(self, other: _Decimal, context: Context | None = None) -> bool: ...

stdlib/builtins.pyi

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class staticmethod(Generic[_R_co]):
117117
@property
118118
def __isabstractmethod__(self) -> bool: ...
119119
def __init__(self: staticmethod[_R_co], __f: Callable[..., _R_co]) -> None: ...
120-
def __get__(self, __obj: _T, __type: type[_T] | None = ...) -> Callable[..., _R_co]: ...
120+
def __get__(self, __instance: _T, __owner: type[_T] | None = None) -> Callable[..., _R_co]: ...
121121
if sys.version_info >= (3, 10):
122122
__name__: str
123123
__qualname__: str
@@ -131,7 +131,7 @@ class classmethod(Generic[_R_co]):
131131
@property
132132
def __isabstractmethod__(self) -> bool: ...
133133
def __init__(self: classmethod[_R_co], __f: Callable[..., _R_co]) -> None: ...
134-
def __get__(self, __obj: _T, __type: type[_T] | None = ...) -> Callable[..., _R_co]: ...
134+
def __get__(self, __instance: _T, __owner: type[_T] | None = None) -> Callable[..., _R_co]: ...
135135
if sys.version_info >= (3, 10):
136136
__name__: str
137137
__qualname__: str
@@ -958,7 +958,7 @@ class function:
958958

959959
__module__: str
960960
# mypy uses `builtins.function.__get__` to represent methods, properties, and getset_descriptors so we type the return as Any.
961-
def __get__(self, obj: object, type: type | None = ...) -> Any: ...
961+
def __get__(self, __instance: object, __owner: type | None = None) -> Any: ...
962962

963963
class list(MutableSequence[_T], Generic[_T]):
964964
@overload
@@ -1185,9 +1185,9 @@ class property:
11851185
def getter(self, __fget: Callable[[Any], Any]) -> property: ...
11861186
def setter(self, __fset: Callable[[Any, Any], None]) -> property: ...
11871187
def deleter(self, __fdel: Callable[[Any], None]) -> property: ...
1188-
def __get__(self, __obj: Any, __type: type | None = ...) -> Any: ...
1189-
def __set__(self, __obj: Any, __value: Any) -> None: ...
1190-
def __delete__(self, __obj: Any) -> None: ...
1188+
def __get__(self, __instance: Any, __owner: type | None = None) -> Any: ...
1189+
def __set__(self, __instance: Any, __value: Any) -> None: ...
1190+
def __delete__(self, __instance: Any) -> None: ...
11911191

11921192
@final
11931193
class _NotImplementedType(Any): # type: ignore[misc]

stdlib/select.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ if sys.platform == "linux":
110110
def __exit__(
111111
self,
112112
__exc_type: type[BaseException] | None = None,
113-
__exc_val: BaseException | None = ...,
113+
__exc_value: BaseException | None = ...,
114114
__exc_tb: TracebackType | None = None,
115115
) -> None: ...
116116
def close(self) -> None: ...

stdlib/types.pyi

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ class FunctionType:
103103
) -> None: ...
104104
def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
105105
@overload
106-
def __get__(self, obj: None, type: type) -> FunctionType: ...
106+
def __get__(self, __instance: None, __owner: type) -> FunctionType: ...
107107
@overload
108-
def __get__(self, obj: object, type: type | None = ...) -> MethodType: ...
108+
def __get__(self, __instance: object, __owner: type | None = None) -> MethodType: ...
109109

110110
LambdaType = FunctionType
111111

@@ -454,7 +454,7 @@ class WrapperDescriptorType:
454454
@property
455455
def __objclass__(self) -> type: ...
456456
def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
457-
def __get__(self, __obj: Any, __type: type = ...) -> Any: ...
457+
def __get__(self, __instance: Any, __owner: type | None = None) -> Any: ...
458458

459459
@final
460460
class MethodWrapperType:
@@ -479,7 +479,7 @@ class MethodDescriptorType:
479479
@property
480480
def __objclass__(self) -> type: ...
481481
def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
482-
def __get__(self, obj: Any, type: type = ...) -> Any: ...
482+
def __get__(self, __instance: Any, __owner: type | None = None) -> Any: ...
483483

484484
@final
485485
class ClassMethodDescriptorType:
@@ -490,7 +490,7 @@ class ClassMethodDescriptorType:
490490
@property
491491
def __objclass__(self) -> type: ...
492492
def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
493-
def __get__(self, obj: Any, type: type = ...) -> Any: ...
493+
def __get__(self, __instance: Any, __owner: type | None = None) -> Any: ...
494494

495495
@final
496496
class TracebackType:
@@ -536,7 +536,7 @@ class GetSetDescriptorType:
536536
def __qualname__(self) -> str: ...
537537
@property
538538
def __objclass__(self) -> type: ...
539-
def __get__(self, __obj: Any, __type: type = ...) -> Any: ...
539+
def __get__(self, __instance: Any, __owner: type | None = None) -> Any: ...
540540
def __set__(self, __instance: Any, __value: Any) -> None: ...
541541
def __delete__(self, __obj: Any) -> None: ...
542542

@@ -548,7 +548,7 @@ class MemberDescriptorType:
548548
def __qualname__(self) -> str: ...
549549
@property
550550
def __objclass__(self) -> type: ...
551-
def __get__(self, __obj: Any, __type: type = ...) -> Any: ...
551+
def __get__(self, __instance: Any, __owner: type | None = None) -> Any: ...
552552
def __set__(self, __instance: Any, __value: Any) -> None: ...
553553
def __delete__(self, __obj: Any) -> None: ...
554554

tests/stubtest_allowlists/py37.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ builtins.property.__get__
157157
builtins.staticmethod.__get__
158158
types.FunctionType.__get__
159159
types.LambdaType.__get__
160+
types.ClassMethodDescriptorType.__get__
161+
types.GetSetDescriptorType.__get__
162+
types.MemberDescriptorType.__get__
163+
types.MethodDescriptorType.__get__
164+
types.WrapperDescriptorType.__get__
160165

161166
# Missing from distutils (deprecated, to be removed in 3.12)
162167
distutils.core.USAGE

tests/stubtest_allowlists/py38.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,11 @@ builtins.property.__get__
174174
builtins.staticmethod.__get__
175175
types.FunctionType.__get__
176176
types.LambdaType.__get__
177+
types.ClassMethodDescriptorType.__get__
178+
types.GetSetDescriptorType.__get__
179+
types.MemberDescriptorType.__get__
180+
types.MethodDescriptorType.__get__
181+
types.WrapperDescriptorType.__get__
177182

178183
# Missing from distutils (deprecated, to be removed in 3.12)
179184
distutils.core.USAGE

tests/stubtest_allowlists/py39.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ builtins.property.__get__
169169
builtins.staticmethod.__get__
170170
types.FunctionType.__get__
171171
types.LambdaType.__get__
172+
types.ClassMethodDescriptorType.__get__
173+
types.GetSetDescriptorType.__get__
174+
types.MemberDescriptorType.__get__
175+
types.MethodDescriptorType.__get__
176+
types.WrapperDescriptorType.__get__
172177

173178
# Missing from distutils (deprecated, to be removed in 3.12)
174179
distutils.core.USAGE

tests/stubtest_allowlists/py3_common.txt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -428,13 +428,6 @@ pickle.Unpickler.memo # undocumented implementation detail, has different type
428428
re.Pattern.scanner # Undocumented and not useful. #6405
429429
tempfile._TemporaryFileWrapper.[\w_]+ # Dynamically specified by __getattr__, and thus don't exist on the class
430430

431-
# Runtime signature is incorrect (https://github.com/python/cpython/issues/93021)
432-
types.ClassMethodDescriptorType.__get__
433-
types.GetSetDescriptorType.__get__
434-
types.MemberDescriptorType.__get__
435-
types.MethodDescriptorType.__get__
436-
types.WrapperDescriptorType.__get__
437-
438431
# Various classes in typing aren't types at runtime. In addition, mypy thinks some special forms are tautologically defined.
439432
typing.[A-Z]\w+
440433
typing_extensions\..*

0 commit comments

Comments
 (0)