Skip to content

Commit 0656fc4

Browse files
authored
Merge pull request numpy#19802 from BvB93/pep-457
STY: Use the new PEP 457 positional-only syntax for typing
2 parents 160ccdb + 8239685 commit 0656fc4

File tree

12 files changed

+270
-235
lines changed

12 files changed

+270
-235
lines changed

numpy/__init__.pyi

Lines changed: 58 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,9 +1184,9 @@ class flatiter(Generic[_NdArraySubClass]):
11841184
self, key: Union[_ArrayLikeInt, slice, ellipsis],
11851185
) -> _NdArraySubClass: ...
11861186
@overload
1187-
def __array__(self: flatiter[ndarray[Any, _DType]], __dtype: None = ...) -> ndarray[Any, _DType]: ...
1187+
def __array__(self: flatiter[ndarray[Any, _DType]], dtype: None = ..., /) -> ndarray[Any, _DType]: ...
11881188
@overload
1189-
def __array__(self, __dtype: _DType) -> ndarray[Any, _DType]: ...
1189+
def __array__(self, dtype: _DType, /) -> ndarray[Any, _DType]: ...
11901190

11911191
_OrderKACF = Optional[L["K", "A", "C", "F"]]
11921192
_OrderACF = Optional[L["A", "C", "F"]]
@@ -1215,7 +1215,7 @@ class _ArrayOrScalarCommon:
12151215
def __str__(self) -> str: ...
12161216
def __repr__(self) -> str: ...
12171217
def __copy__(self: _ArraySelf) -> _ArraySelf: ...
1218-
def __deepcopy__(self: _ArraySelf, __memo: Optional[dict] = ...) -> _ArraySelf: ...
1218+
def __deepcopy__(self: _ArraySelf, memo: None | dict = ..., /) -> _ArraySelf: ...
12191219
def __eq__(self, other): ...
12201220
def __ne__(self, other): ...
12211221
def copy(self: _ArraySelf, order: _OrderKACF = ...) -> _ArraySelf: ...
@@ -1238,7 +1238,7 @@ class _ArrayOrScalarCommon:
12381238
def __array_priority__(self) -> float: ...
12391239
@property
12401240
def __array_struct__(self): ...
1241-
def __setstate__(self, __state): ...
1241+
def __setstate__(self, state, /): ...
12421242
# a `bool_` is returned when `keepdims=True` and `self` is a 0d array
12431243

12441244
@overload
@@ -1648,7 +1648,7 @@ _ArrayNumber_co = NDArray[Union[bool_, number[Any]]]
16481648
_ArrayTD64_co = NDArray[Union[bool_, integer[Any], timedelta64]]
16491649

16501650
class _SupportsItem(Protocol[_T_co]):
1651-
def item(self, __args: Any) -> _T_co: ...
1651+
def item(self, args: Any, /) -> _T_co: ...
16521652

16531653
class _SupportsReal(Protocol[_T_co]):
16541654
@property
@@ -1687,20 +1687,22 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType, _DType_co]):
16871687
order: _OrderKACF = ...,
16881688
) -> _ArraySelf: ...
16891689
@overload
1690-
def __array__(self, __dtype: None = ...) -> ndarray[Any, _DType_co]: ...
1690+
def __array__(self, dtype: None = ..., /) -> ndarray[Any, _DType_co]: ...
16911691
@overload
1692-
def __array__(self, __dtype: _DType) -> ndarray[Any, _DType]: ...
1692+
def __array__(self, dtype: _DType, /) -> ndarray[Any, _DType]: ...
16931693

16941694
def __array_wrap__(
16951695
self,
1696-
__array: ndarray[_ShapeType2, _DType],
1697-
__context: None | Tuple[ufunc, Tuple[Any, ...], int] = ...,
1696+
array: ndarray[_ShapeType2, _DType],
1697+
context: None | Tuple[ufunc, Tuple[Any, ...], int] = ...,
1698+
/,
16981699
) -> ndarray[_ShapeType2, _DType]: ...
16991700

17001701
def __array_prepare__(
17011702
self,
1702-
__array: ndarray[_ShapeType2, _DType],
1703-
__context: None | Tuple[ufunc, Tuple[Any, ...], int] = ...,
1703+
array: ndarray[_ShapeType2, _DType],
1704+
context: None | Tuple[ufunc, Tuple[Any, ...], int] = ...,
1705+
/,
17041706
) -> ndarray[_ShapeType2, _DType]: ...
17051707

17061708
@property
@@ -1727,16 +1729,17 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType, _DType_co]):
17271729
@overload
17281730
def item(
17291731
self: ndarray[Any, dtype[_SupportsItem[_T]]], # type: ignore[type-var]
1730-
__args: Tuple[SupportsIndex, ...],
1732+
args: Tuple[SupportsIndex, ...],
1733+
/,
17311734
) -> _T: ...
17321735

17331736
@overload
1734-
def itemset(self, __value: Any) -> None: ...
1737+
def itemset(self, value: Any, /) -> None: ...
17351738
@overload
1736-
def itemset(self, __item: _ShapeLike, __value: Any) -> None: ...
1739+
def itemset(self, item: _ShapeLike, value: Any, /) -> None: ...
17371740

17381741
@overload
1739-
def resize(self, __new_shape: _ShapeLike, *, refcheck: bool = ...) -> None: ...
1742+
def resize(self, new_shape: _ShapeLike, /, *, refcheck: bool = ...) -> None: ...
17401743
@overload
17411744
def resize(self, *new_shape: SupportsIndex, refcheck: bool = ...) -> None: ...
17421745

@@ -1756,7 +1759,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType, _DType_co]):
17561759
) -> ndarray[Any, _DType_co]: ...
17571760

17581761
@overload
1759-
def transpose(self: _ArraySelf, __axes: _ShapeLike) -> _ArraySelf: ...
1762+
def transpose(self: _ArraySelf, axes: _ShapeLike, /) -> _ArraySelf: ...
17601763
@overload
17611764
def transpose(self: _ArraySelf, *axes: SupportsIndex) -> _ArraySelf: ...
17621765

@@ -1895,7 +1898,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType, _DType_co]):
18951898

18961899
@overload
18971900
def reshape(
1898-
self, __shape: _ShapeLike, *, order: _OrderACF = ...
1901+
self, shape: _ShapeLike, /, *, order: _OrderACF = ...
18991902
) -> ndarray[Any, _DType_co]: ...
19001903
@overload
19011904
def reshape(
@@ -2901,9 +2904,9 @@ class generic(_ArrayOrScalarCommon):
29012904
@abstractmethod
29022905
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
29032906
@overload
2904-
def __array__(self: _ScalarType, __dtype: None = ...) -> ndarray[Any, dtype[_ScalarType]]: ...
2907+
def __array__(self: _ScalarType, dtype: None = ..., /) -> ndarray[Any, dtype[_ScalarType]]: ...
29052908
@overload
2906-
def __array__(self, __dtype: _DType) -> ndarray[Any, _DType]: ...
2909+
def __array__(self, dtype: _DType, /) -> ndarray[Any, _DType]: ...
29072910
@property
29082911
def base(self) -> None: ...
29092912
@property
@@ -2971,8 +2974,7 @@ class generic(_ArrayOrScalarCommon):
29712974
) -> Any: ...
29722975

29732976
def item(
2974-
self,
2975-
__args: Union[L[0], Tuple[()], Tuple[L[0]]] = ...,
2977+
self, args: L[0] | Tuple[()] | Tuple[L[0]] = ..., /,
29762978
) -> Any: ...
29772979

29782980
@overload
@@ -3018,7 +3020,7 @@ class generic(_ArrayOrScalarCommon):
30183020

30193021
@overload
30203022
def reshape(
3021-
self: _ScalarType, __shape: _ShapeLike, *, order: _OrderACF = ...
3023+
self: _ScalarType, shape: _ShapeLike, /, *, order: _OrderACF = ...
30223024
) -> ndarray[Any, dtype[_ScalarType]]: ...
30233025
@overload
30243026
def reshape(
@@ -3028,7 +3030,7 @@ class generic(_ArrayOrScalarCommon):
30283030
def squeeze(
30293031
self: _ScalarType, axis: Union[L[0], Tuple[()]] = ...
30303032
) -> _ScalarType: ...
3031-
def transpose(self: _ScalarType, __axes: Tuple[()] = ...) -> _ScalarType: ...
3033+
def transpose(self: _ScalarType, axes: Tuple[()] = ..., /) -> _ScalarType: ...
30323034
# Keep `dtype` at the bottom to avoid name conflicts with `np.dtype`
30333035
@property
30343036
def dtype(self: _ScalarType) -> dtype[_ScalarType]: ...
@@ -3063,10 +3065,9 @@ class number(generic, Generic[_NBit1]): # type: ignore
30633065
__ge__: _ComparisonOp[_NumberLike_co, _ArrayLikeNumber_co]
30643066

30653067
class bool_(generic):
3066-
def __init__(self, __value: object = ...) -> None: ...
3068+
def __init__(self, value: object = ..., /) -> None: ...
30673069
def item(
3068-
self,
3069-
__args: Union[L[0], Tuple[()], Tuple[L[0]]] = ...,
3070+
self, args: L[0] | Tuple[()] | Tuple[L[0]] = ..., /,
30703071
) -> bool: ...
30713072
def tolist(self) -> bool: ...
30723073
@property
@@ -3112,7 +3113,7 @@ class bool_(generic):
31123113
bool8 = bool_
31133114

31143115
class object_(generic):
3115-
def __init__(self, __value: object = ...) -> None: ...
3116+
def __init__(self, value: object = ..., /) -> None: ...
31163117
@property
31173118
def real(self: _ArraySelf) -> _ArraySelf: ...
31183119
@property
@@ -3141,14 +3142,16 @@ class datetime64(generic):
31413142
@overload
31423143
def __init__(
31433144
self,
3144-
__value: Union[None, datetime64, _CharLike_co, _DatetimeScalar] = ...,
3145-
__format: Union[_CharLike_co, Tuple[_CharLike_co, _IntLike_co]] = ...,
3145+
value: None | datetime64 | _CharLike_co | _DatetimeScalar = ...,
3146+
format: _CharLike_co | Tuple[_CharLike_co, _IntLike_co] = ...,
3147+
/,
31463148
) -> None: ...
31473149
@overload
31483150
def __init__(
31493151
self,
3150-
__value: int,
3151-
__format: Union[_CharLike_co, Tuple[_CharLike_co, _IntLike_co]]
3152+
value: int,
3153+
format: _CharLike_co | Tuple[_CharLike_co, _IntLike_co],
3154+
/,
31523155
) -> None: ...
31533156
def __add__(self, other: _TD64Like_co) -> datetime64: ...
31543157
def __radd__(self, other: _TD64Like_co) -> datetime64: ...
@@ -3186,8 +3189,7 @@ class integer(number[_NBit1]): # type: ignore
31863189
# NOTE: `__index__` is technically defined in the bottom-most
31873190
# sub-classes (`int64`, `uint32`, etc)
31883191
def item(
3189-
self,
3190-
__args: Union[L[0], Tuple[()], Tuple[L[0]]] = ...,
3192+
self, args: L[0] | Tuple[()] | Tuple[L[0]] = ..., /,
31913193
) -> int: ...
31923194
def tolist(self) -> int: ...
31933195
def __index__(self) -> int: ...
@@ -3209,7 +3211,7 @@ class integer(number[_NBit1]): # type: ignore
32093211
def __rxor__(self, other: _IntLike_co) -> integer: ...
32103212

32113213
class signedinteger(integer[_NBit1]):
3212-
def __init__(self, __value: _IntValue = ...) -> None: ...
3214+
def __init__(self, value: _IntValue = ..., /) -> None: ...
32133215
__add__: _SignedIntOp[_NBit1]
32143216
__radd__: _SignedIntOp[_NBit1]
32153217
__sub__: _SignedIntOp[_NBit1]
@@ -3253,8 +3255,9 @@ longlong = signedinteger[_NBitLongLong]
32533255
class timedelta64(generic):
32543256
def __init__(
32553257
self,
3256-
__value: Union[None, int, _CharLike_co, dt.timedelta, timedelta64] = ...,
3257-
__format: Union[_CharLike_co, Tuple[_CharLike_co, _IntLike_co]] = ...,
3258+
value: None | int | _CharLike_co | dt.timedelta | timedelta64 = ...,
3259+
format: _CharLike_co | Tuple[_CharLike_co, _IntLike_co] = ...,
3260+
/,
32583261
) -> None: ...
32593262
@property
32603263
def numerator(self: _ScalarType) -> _ScalarType: ...
@@ -3290,7 +3293,7 @@ class timedelta64(generic):
32903293

32913294
class unsignedinteger(integer[_NBit1]):
32923295
# NOTE: `uint64 + signedinteger -> float64`
3293-
def __init__(self, __value: _IntValue = ...) -> None: ...
3296+
def __init__(self, value: _IntValue = ..., /) -> None: ...
32943297
__add__: _UnsignedIntOp[_NBit1]
32953298
__radd__: _UnsignedIntOp[_NBit1]
32963299
__sub__: _UnsignedIntOp[_NBit1]
@@ -3336,23 +3339,23 @@ _IntType = TypeVar("_IntType", bound=integer)
33363339
_FloatType = TypeVar('_FloatType', bound=floating)
33373340

33383341
class floating(inexact[_NBit1]):
3339-
def __init__(self, __value: _FloatValue = ...) -> None: ...
3342+
def __init__(self, value: _FloatValue = ..., /) -> None: ...
33403343
def item(
3341-
self,
3342-
__args: Union[L[0], Tuple[()], Tuple[L[0]]] = ...,
3344+
self, args: L[0] | Tuple[()] | Tuple[L[0]] = ...,
3345+
/,
33433346
) -> float: ...
33443347
def tolist(self) -> float: ...
33453348
def is_integer(self: float64) -> bool: ...
33463349
def hex(self: float64) -> str: ...
33473350
@classmethod
3348-
def fromhex(cls: Type[float64], __string: str) -> float64: ...
3351+
def fromhex(cls: Type[float64], string: str, /) -> float64: ...
33493352
def as_integer_ratio(self) -> Tuple[int, int]: ...
33503353
if sys.version_info >= (3, 9):
33513354
def __ceil__(self: float64) -> int: ...
33523355
def __floor__(self: float64) -> int: ...
33533356
def __trunc__(self: float64) -> int: ...
33543357
def __getnewargs__(self: float64) -> Tuple[float]: ...
3355-
def __getformat__(self: float64, __typestr: L["double", "float"]) -> str: ...
3358+
def __getformat__(self: float64, typestr: L["double", "float"], /) -> str: ...
33563359
@overload
33573360
def __round__(self, ndigits: None = ...) -> int: ...
33583361
@overload
@@ -3390,10 +3393,9 @@ longfloat = floating[_NBitLongDouble]
33903393
# describing the two 64 bit floats representing its real and imaginary component
33913394

33923395
class complexfloating(inexact[_NBit1], Generic[_NBit1, _NBit2]):
3393-
def __init__(self, __value: _ComplexValue = ...) -> None: ...
3396+
def __init__(self, value: _ComplexValue = ..., /) -> None: ...
33943397
def item(
3395-
self,
3396-
__args: Union[L[0], Tuple[()], Tuple[L[0]]] = ...,
3398+
self, args: L[0] | Tuple[()] | Tuple[L[0]] = ..., /,
33973399
) -> complex: ...
33983400
def tolist(self) -> complex: ...
33993401
@property
@@ -3433,7 +3435,7 @@ class flexible(generic): ... # type: ignore
34333435
# depending on whether or not it's used as an opaque bytes sequence
34343436
# or a structure
34353437
class void(flexible):
3436-
def __init__(self, __value: Union[_IntLike_co, bytes]) -> None: ...
3438+
def __init__(self, value: _IntLike_co | bytes, /) -> None: ...
34373439
@property
34383440
def real(self: _ArraySelf) -> _ArraySelf: ...
34393441
@property
@@ -3455,14 +3457,13 @@ class character(flexible): # type: ignore
34553457

34563458
class bytes_(character, bytes):
34573459
@overload
3458-
def __init__(self, __value: object = ...) -> None: ...
3460+
def __init__(self, value: object = ..., /) -> None: ...
34593461
@overload
34603462
def __init__(
3461-
self, __value: str, encoding: str = ..., errors: str = ...
3463+
self, value: str, /, encoding: str = ..., errors: str = ...
34623464
) -> None: ...
34633465
def item(
3464-
self,
3465-
__args: Union[L[0], Tuple[()], Tuple[L[0]]] = ...,
3466+
self, args: L[0] | Tuple[()] | Tuple[L[0]] = ..., /,
34663467
) -> bytes: ...
34673468
def tolist(self) -> bytes: ...
34683469

@@ -3471,14 +3472,13 @@ bytes0 = bytes_
34713472

34723473
class str_(character, str):
34733474
@overload
3474-
def __init__(self, __value: object = ...) -> None: ...
3475+
def __init__(self, value: object = ..., /) -> None: ...
34753476
@overload
34763477
def __init__(
3477-
self, __value: bytes, encoding: str = ..., errors: str = ...
3478+
self, value: bytes, /, encoding: str = ..., errors: str = ...
34783479
) -> None: ...
34793480
def item(
3480-
self,
3481-
__args: Union[L[0], Tuple[()], Tuple[L[0]]] = ...,
3481+
self, args: L[0] | Tuple[()] | Tuple[L[0]] = ..., /,
34823482
) -> str: ...
34833483
def tolist(self) -> str: ...
34843484

@@ -3712,9 +3712,10 @@ class errstate(Generic[_CallType], ContextDecorator):
37123712
def __enter__(self) -> None: ...
37133713
def __exit__(
37143714
self,
3715-
__exc_type: Optional[Type[BaseException]],
3716-
__exc_value: Optional[BaseException],
3717-
__traceback: Optional[TracebackType],
3715+
exc_type: Optional[Type[BaseException]],
3716+
exc_value: Optional[BaseException],
3717+
traceback: Optional[TracebackType],
3718+
/,
37183719
) -> None: ...
37193720

37203721
class ndenumerate(Generic[_ScalarType]):

numpy/core/_ufunc_config.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ _ErrKind = Literal["ignore", "warn", "raise", "call", "print", "log"]
44
_ErrFunc = Callable[[str, int], Any]
55

66
class _SupportsWrite(Protocol):
7-
def write(self, __msg: str) -> Any: ...
7+
def write(self, msg: str, /) -> Any: ...
88

99
class _ErrDict(TypedDict):
1010
divide: _ErrKind

0 commit comments

Comments
 (0)