Skip to content

Commit bee1e1f

Browse files
authored
Add default argument values to builtin types (#14824)
Mark two exception `name` arguments as being potentially `None`
1 parent e6f5183 commit bee1e1f

File tree

1 file changed

+62
-55
lines changed

1 file changed

+62
-55
lines changed

stdlib/builtins.pyi

Lines changed: 62 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ _LiteralInteger = _PositiveInteger | _NegativeInteger | Literal[0] # noqa: Y026
252252
@disjoint_base
253253
class int:
254254
@overload
255-
def __new__(cls, x: ConvertibleToInt = ..., /) -> Self: ...
255+
def __new__(cls, x: ConvertibleToInt = 0, /) -> Self: ...
256256
@overload
257257
def __new__(cls, x: str | bytes | bytearray, /, base: SupportsIndex) -> Self: ...
258258
def as_integer_ratio(self) -> tuple[int, Literal[1]]: ...
@@ -362,7 +362,7 @@ class int:
362362

363363
@disjoint_base
364364
class float:
365-
def __new__(cls, x: ConvertibleToFloat = ..., /) -> Self: ...
365+
def __new__(cls, x: ConvertibleToFloat = 0, /) -> Self: ...
366366
def as_integer_ratio(self) -> tuple[int, int]: ...
367367
def hex(self) -> str: ...
368368
def is_integer(self) -> bool: ...
@@ -432,8 +432,8 @@ class complex:
432432
@overload
433433
def __new__(
434434
cls,
435-
real: complex | SupportsComplex | SupportsFloat | SupportsIndex = ...,
436-
imag: complex | SupportsFloat | SupportsIndex = ...,
435+
real: complex | SupportsComplex | SupportsFloat | SupportsIndex = 0,
436+
imag: complex | SupportsFloat | SupportsIndex = 0,
437437
) -> Self: ...
438438
@overload
439439
def __new__(cls, real: str | SupportsComplex | SupportsFloat | SupportsIndex | complex) -> Self: ...
@@ -477,9 +477,9 @@ class _TranslateTable(Protocol):
477477
@disjoint_base
478478
class str(Sequence[str]):
479479
@overload
480-
def __new__(cls, object: object = ...) -> Self: ...
480+
def __new__(cls, object: object = "") -> Self: ...
481481
@overload
482-
def __new__(cls, object: ReadableBuffer, encoding: str = ..., errors: str = ...) -> Self: ...
482+
def __new__(cls, object: ReadableBuffer, encoding: str = "utf-8", errors: str = "strict") -> Self: ...
483483
@overload
484484
def capitalize(self: LiteralString) -> LiteralString: ...
485485
@overload
@@ -492,22 +492,22 @@ class str(Sequence[str]):
492492
def center(self: LiteralString, width: SupportsIndex, fillchar: LiteralString = " ", /) -> LiteralString: ...
493493
@overload
494494
def center(self, width: SupportsIndex, fillchar: str = " ", /) -> str: ... # type: ignore[misc]
495-
def count(self, sub: str, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /) -> int: ...
495+
def count(self, sub: str, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /) -> int: ...
496496
def encode(self, encoding: str = "utf-8", errors: str = "strict") -> bytes: ...
497497
def endswith(
498-
self, suffix: str | tuple[str, ...], start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /
498+
self, suffix: str | tuple[str, ...], start: SupportsIndex | None = None, end: SupportsIndex | None = None, /
499499
) -> bool: ...
500500
@overload
501501
def expandtabs(self: LiteralString, tabsize: SupportsIndex = 8) -> LiteralString: ...
502502
@overload
503503
def expandtabs(self, tabsize: SupportsIndex = 8) -> str: ... # type: ignore[misc]
504-
def find(self, sub: str, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /) -> int: ...
504+
def find(self, sub: str, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /) -> int: ...
505505
@overload
506506
def format(self: LiteralString, *args: LiteralString, **kwargs: LiteralString) -> LiteralString: ...
507507
@overload
508508
def format(self, *args: object, **kwargs: object) -> str: ...
509509
def format_map(self, mapping: _FormatMapMapping, /) -> str: ...
510-
def index(self, sub: str, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /) -> int: ...
510+
def index(self, sub: str, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /) -> int: ...
511511
def isalnum(self) -> bool: ...
512512
def isalpha(self) -> bool: ...
513513
def isascii(self) -> bool: ...
@@ -563,8 +563,8 @@ class str(Sequence[str]):
563563
def removesuffix(self: LiteralString, suffix: LiteralString, /) -> LiteralString: ...
564564
@overload
565565
def removesuffix(self, suffix: str, /) -> str: ... # type: ignore[misc]
566-
def rfind(self, sub: str, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /) -> int: ...
567-
def rindex(self, sub: str, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /) -> int: ...
566+
def rfind(self, sub: str, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /) -> int: ...
567+
def rindex(self, sub: str, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /) -> int: ...
568568
@overload
569569
def rjust(self: LiteralString, width: SupportsIndex, fillchar: LiteralString = " ", /) -> LiteralString: ...
570570
@overload
@@ -590,7 +590,7 @@ class str(Sequence[str]):
590590
@overload
591591
def splitlines(self, keepends: bool = False) -> list[str]: ... # type: ignore[misc]
592592
def startswith(
593-
self, prefix: str | tuple[str, ...], start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /
593+
self, prefix: str | tuple[str, ...], start: SupportsIndex | None = None, end: SupportsIndex | None = None, /
594594
) -> bool: ...
595595
@overload
596596
def strip(self: LiteralString, chars: LiteralString | None = None, /) -> LiteralString: ...
@@ -664,29 +664,29 @@ class bytes(Sequence[int]):
664664
@overload
665665
def __new__(cls, o: Iterable[SupportsIndex] | SupportsIndex | SupportsBytes | ReadableBuffer, /) -> Self: ...
666666
@overload
667-
def __new__(cls, string: str, /, encoding: str, errors: str = ...) -> Self: ...
667+
def __new__(cls, string: str, /, encoding: str, errors: str = "strict") -> Self: ...
668668
@overload
669669
def __new__(cls) -> Self: ...
670670
def capitalize(self) -> bytes: ...
671671
def center(self, width: SupportsIndex, fillchar: bytes = b" ", /) -> bytes: ...
672672
def count(
673-
self, sub: ReadableBuffer | SupportsIndex, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /
673+
self, sub: ReadableBuffer | SupportsIndex, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /
674674
) -> int: ...
675675
def decode(self, encoding: str = "utf-8", errors: str = "strict") -> str: ...
676676
def endswith(
677677
self,
678678
suffix: ReadableBuffer | tuple[ReadableBuffer, ...],
679-
start: SupportsIndex | None = ...,
680-
end: SupportsIndex | None = ...,
679+
start: SupportsIndex | None = None,
680+
end: SupportsIndex | None = None,
681681
/,
682682
) -> bool: ...
683683
def expandtabs(self, tabsize: SupportsIndex = 8) -> bytes: ...
684684
def find(
685-
self, sub: ReadableBuffer | SupportsIndex, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /
685+
self, sub: ReadableBuffer | SupportsIndex, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /
686686
) -> int: ...
687-
def hex(self, sep: str | bytes = ..., bytes_per_sep: SupportsIndex = ...) -> str: ...
687+
def hex(self, sep: str | bytes = ..., bytes_per_sep: SupportsIndex = 1) -> str: ...
688688
def index(
689-
self, sub: ReadableBuffer | SupportsIndex, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /
689+
self, sub: ReadableBuffer | SupportsIndex, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /
690690
) -> int: ...
691691
def isalnum(self) -> bool: ...
692692
def isalpha(self) -> bool: ...
@@ -705,10 +705,10 @@ class bytes(Sequence[int]):
705705
def removeprefix(self, prefix: ReadableBuffer, /) -> bytes: ...
706706
def removesuffix(self, suffix: ReadableBuffer, /) -> bytes: ...
707707
def rfind(
708-
self, sub: ReadableBuffer | SupportsIndex, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /
708+
self, sub: ReadableBuffer | SupportsIndex, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /
709709
) -> int: ...
710710
def rindex(
711-
self, sub: ReadableBuffer | SupportsIndex, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /
711+
self, sub: ReadableBuffer | SupportsIndex, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /
712712
) -> int: ...
713713
def rjust(self, width: SupportsIndex, fillchar: bytes | bytearray = b" ", /) -> bytes: ...
714714
def rpartition(self, sep: ReadableBuffer, /) -> tuple[bytes, bytes, bytes]: ...
@@ -719,8 +719,8 @@ class bytes(Sequence[int]):
719719
def startswith(
720720
self,
721721
prefix: ReadableBuffer | tuple[ReadableBuffer, ...],
722-
start: SupportsIndex | None = ...,
723-
end: SupportsIndex | None = ...,
722+
start: SupportsIndex | None = None,
723+
end: SupportsIndex | None = None,
724724
/,
725725
) -> bool: ...
726726
def strip(self, bytes: ReadableBuffer | None = None, /) -> bytes: ...
@@ -765,30 +765,30 @@ class bytearray(MutableSequence[int]):
765765
@overload
766766
def __init__(self, ints: Iterable[SupportsIndex] | SupportsIndex | ReadableBuffer, /) -> None: ...
767767
@overload
768-
def __init__(self, string: str, /, encoding: str, errors: str = ...) -> None: ...
768+
def __init__(self, string: str, /, encoding: str, errors: str = "strict") -> None: ...
769769
def append(self, item: SupportsIndex, /) -> None: ...
770770
def capitalize(self) -> bytearray: ...
771771
def center(self, width: SupportsIndex, fillchar: bytes = b" ", /) -> bytearray: ...
772772
def count(
773-
self, sub: ReadableBuffer | SupportsIndex, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /
773+
self, sub: ReadableBuffer | SupportsIndex, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /
774774
) -> int: ...
775775
def copy(self) -> bytearray: ...
776776
def decode(self, encoding: str = "utf-8", errors: str = "strict") -> str: ...
777777
def endswith(
778778
self,
779779
suffix: ReadableBuffer | tuple[ReadableBuffer, ...],
780-
start: SupportsIndex | None = ...,
781-
end: SupportsIndex | None = ...,
780+
start: SupportsIndex | None = None,
781+
end: SupportsIndex | None = None,
782782
/,
783783
) -> bool: ...
784784
def expandtabs(self, tabsize: SupportsIndex = 8) -> bytearray: ...
785785
def extend(self, iterable_of_ints: Iterable[SupportsIndex], /) -> None: ...
786786
def find(
787-
self, sub: ReadableBuffer | SupportsIndex, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /
787+
self, sub: ReadableBuffer | SupportsIndex, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /
788788
) -> int: ...
789-
def hex(self, sep: str | bytes = ..., bytes_per_sep: SupportsIndex = ...) -> str: ...
789+
def hex(self, sep: str | bytes = ..., bytes_per_sep: SupportsIndex = 1) -> str: ...
790790
def index(
791-
self, sub: ReadableBuffer | SupportsIndex, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /
791+
self, sub: ReadableBuffer | SupportsIndex, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /
792792
) -> int: ...
793793
def insert(self, index: SupportsIndex, item: SupportsIndex, /) -> None: ...
794794
def isalnum(self) -> bool: ...
@@ -810,10 +810,10 @@ class bytearray(MutableSequence[int]):
810810
def removesuffix(self, suffix: ReadableBuffer, /) -> bytearray: ...
811811
def replace(self, old: ReadableBuffer, new: ReadableBuffer, count: SupportsIndex = -1, /) -> bytearray: ...
812812
def rfind(
813-
self, sub: ReadableBuffer | SupportsIndex, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /
813+
self, sub: ReadableBuffer | SupportsIndex, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /
814814
) -> int: ...
815815
def rindex(
816-
self, sub: ReadableBuffer | SupportsIndex, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /
816+
self, sub: ReadableBuffer | SupportsIndex, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /
817817
) -> int: ...
818818
def rjust(self, width: SupportsIndex, fillchar: bytes | bytearray = b" ", /) -> bytearray: ...
819819
def rpartition(self, sep: ReadableBuffer, /) -> tuple[bytearray, bytearray, bytearray]: ...
@@ -824,8 +824,8 @@ class bytearray(MutableSequence[int]):
824824
def startswith(
825825
self,
826826
prefix: ReadableBuffer | tuple[ReadableBuffer, ...],
827-
start: SupportsIndex | None = ...,
828-
end: SupportsIndex | None = ...,
827+
start: SupportsIndex | None = None,
828+
end: SupportsIndex | None = None,
829829
/,
830830
) -> bool: ...
831831
def strip(self, bytes: ReadableBuffer | None = None, /) -> bytearray: ...
@@ -939,7 +939,7 @@ class memoryview(Sequence[_I]):
939939
def tolist(self) -> list[int]: ...
940940
def toreadonly(self) -> memoryview: ...
941941
def release(self) -> None: ...
942-
def hex(self, sep: str | bytes = ..., bytes_per_sep: SupportsIndex = ...) -> str: ...
942+
def hex(self, sep: str | bytes = ..., bytes_per_sep: SupportsIndex = 1) -> str: ...
943943
def __buffer__(self, flags: int, /) -> memoryview: ...
944944
def __release_buffer__(self, buffer: memoryview, /) -> None: ...
945945

@@ -952,7 +952,7 @@ class memoryview(Sequence[_I]):
952952

953953
@final
954954
class bool(int):
955-
def __new__(cls, o: object = ..., /) -> Self: ...
955+
def __new__(cls, o: object = False, /) -> Self: ...
956956
# The following overloads could be represented more elegantly with a TypeVar("_B", bool, int),
957957
# however mypy has a bug regarding TypeVar constraints (https://github.com/python/mypy/issues/11880).
958958
@overload
@@ -1025,7 +1025,7 @@ class slice(Generic[_StartT_co, _StopT_co, _StepT_co]):
10251025

10261026
@disjoint_base
10271027
class tuple(Sequence[_T_co]):
1028-
def __new__(cls, iterable: Iterable[_T_co] = ..., /) -> Self: ...
1028+
def __new__(cls, iterable: Iterable[_T_co] = (), /) -> Self: ...
10291029
def __len__(self) -> int: ...
10301030
def __contains__(self, key: object, /) -> bool: ...
10311031
@overload
@@ -1325,7 +1325,7 @@ class range(Sequence[int]):
13251325
@overload
13261326
def __new__(cls, stop: SupportsIndex, /) -> Self: ...
13271327
@overload
1328-
def __new__(cls, start: SupportsIndex, stop: SupportsIndex, step: SupportsIndex = ..., /) -> Self: ...
1328+
def __new__(cls, start: SupportsIndex, stop: SupportsIndex, step: SupportsIndex = 1, /) -> Self: ...
13291329
def count(self, value: int, /) -> int: ...
13301330
def index(self, value: int, /) -> int: ... # type: ignore[override]
13311331
def __len__(self) -> int: ...
@@ -1350,10 +1350,10 @@ class property:
13501350

13511351
def __init__(
13521352
self,
1353-
fget: Callable[[Any], Any] | None = ...,
1354-
fset: Callable[[Any, Any], None] | None = ...,
1355-
fdel: Callable[[Any], None] | None = ...,
1356-
doc: str | None = ...,
1353+
fget: Callable[[Any], Any] | None = None,
1354+
fset: Callable[[Any, Any], None] | None = None,
1355+
fdel: Callable[[Any], None] | None = None,
1356+
doc: str | None = None,
13571357
) -> None: ...
13581358
def getter(self, fget: Callable[[Any], Any], /) -> property: ...
13591359
def setter(self, fset: Callable[[Any, Any], None], /) -> property: ...
@@ -1940,18 +1940,25 @@ def vars(object: Any = ..., /) -> dict[str, Any]: ...
19401940
class zip(Generic[_T_co]):
19411941
if sys.version_info >= (3, 10):
19421942
@overload
1943-
def __new__(cls, *, strict: bool = ...) -> zip[Any]: ...
1943+
def __new__(cls, *, strict: bool = False) -> zip[Any]: ...
19441944
@overload
1945-
def __new__(cls, iter1: Iterable[_T1], /, *, strict: bool = ...) -> zip[tuple[_T1]]: ...
1945+
def __new__(cls, iter1: Iterable[_T1], /, *, strict: bool = False) -> zip[tuple[_T1]]: ...
19461946
@overload
1947-
def __new__(cls, iter1: Iterable[_T1], iter2: Iterable[_T2], /, *, strict: bool = ...) -> zip[tuple[_T1, _T2]]: ...
1947+
def __new__(cls, iter1: Iterable[_T1], iter2: Iterable[_T2], /, *, strict: bool = False) -> zip[tuple[_T1, _T2]]: ...
19481948
@overload
19491949
def __new__(
1950-
cls, iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], /, *, strict: bool = ...
1950+
cls, iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], /, *, strict: bool = False
19511951
) -> zip[tuple[_T1, _T2, _T3]]: ...
19521952
@overload
19531953
def __new__(
1954-
cls, iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], iter4: Iterable[_T4], /, *, strict: bool = ...
1954+
cls,
1955+
iter1: Iterable[_T1],
1956+
iter2: Iterable[_T2],
1957+
iter3: Iterable[_T3],
1958+
iter4: Iterable[_T4],
1959+
/,
1960+
*,
1961+
strict: bool = False,
19551962
) -> zip[tuple[_T1, _T2, _T3, _T4]]: ...
19561963
@overload
19571964
def __new__(
@@ -1963,7 +1970,7 @@ class zip(Generic[_T_co]):
19631970
iter5: Iterable[_T5],
19641971
/,
19651972
*,
1966-
strict: bool = ...,
1973+
strict: bool = False,
19671974
) -> zip[tuple[_T1, _T2, _T3, _T4, _T5]]: ...
19681975
@overload
19691976
def __new__(
@@ -1976,7 +1983,7 @@ class zip(Generic[_T_co]):
19761983
iter6: Iterable[Any],
19771984
/,
19781985
*iterables: Iterable[Any],
1979-
strict: bool = ...,
1986+
strict: bool = False,
19801987
) -> zip[tuple[Any, ...]]: ...
19811988
else:
19821989
@overload
@@ -2090,8 +2097,8 @@ class AssertionError(Exception): ...
20902097
if sys.version_info >= (3, 10):
20912098
@disjoint_base
20922099
class AttributeError(Exception):
2093-
def __init__(self, *args: object, name: str | None = ..., obj: object = ...) -> None: ...
2094-
name: str
2100+
def __init__(self, *args: object, name: str | None = None, obj: object = None) -> None: ...
2101+
name: str | None
20952102
obj: object
20962103

20972104
else:
@@ -2102,7 +2109,7 @@ class EOFError(Exception): ...
21022109

21032110
@disjoint_base
21042111
class ImportError(Exception):
2105-
def __init__(self, *args: object, name: str | None = ..., path: str | None = ...) -> None: ...
2112+
def __init__(self, *args: object, name: str | None = None, path: str | None = None) -> None: ...
21062113
name: str | None
21072114
path: str | None
21082115
msg: str # undocumented
@@ -2115,8 +2122,8 @@ class MemoryError(Exception): ...
21152122
if sys.version_info >= (3, 10):
21162123
@disjoint_base
21172124
class NameError(Exception):
2118-
def __init__(self, *args: object, name: str | None = ...) -> None: ...
2119-
name: str
2125+
def __init__(self, *args: object, name: str | None = None) -> None: ...
2126+
name: str | None
21202127

21212128
else:
21222129
class NameError(Exception): ...

0 commit comments

Comments
 (0)