@@ -63,6 +63,7 @@ from typing import ( # noqa: Y022,UP035
6363from typing_extensions import ( # noqa: Y023
6464 Concatenate ,
6565 Literal ,
66+ LiteralString ,
6667 ParamSpec ,
6768 Self ,
6869 TypeAlias ,
@@ -477,16 +478,31 @@ class str(Sequence[str]):
477478 def __new__ (cls , object : object = ...) -> Self : ...
478479 @overload
479480 def __new__ (cls , object : ReadableBuffer , encoding : str = ..., errors : str = ...) -> Self : ...
481+ @overload
482+ def capitalize (self : LiteralString ) -> LiteralString : ...
483+ @overload
480484 def capitalize (self ) -> str : ... # type: ignore[misc]
485+ @overload
486+ def casefold (self : LiteralString ) -> LiteralString : ...
487+ @overload
481488 def casefold (self ) -> str : ... # type: ignore[misc]
489+ @overload
490+ def center (self : LiteralString , width : SupportsIndex , fillchar : LiteralString = " " , / ) -> LiteralString : ...
491+ @overload
482492 def center (self , width : SupportsIndex , fillchar : str = " " , / ) -> str : ... # type: ignore[misc]
483493 def count (self , sub : str , start : SupportsIndex | None = ..., end : SupportsIndex | None = ..., / ) -> int : ...
484494 def encode (self , encoding : str = "utf-8" , errors : str = "strict" ) -> bytes : ...
485495 def endswith (
486496 self , suffix : str | tuple [str , ...], start : SupportsIndex | None = ..., end : SupportsIndex | None = ..., /
487497 ) -> bool : ...
498+ @overload
499+ def expandtabs (self : LiteralString , tabsize : SupportsIndex = 8 ) -> LiteralString : ...
500+ @overload
488501 def expandtabs (self , tabsize : SupportsIndex = 8 ) -> str : ... # type: ignore[misc]
489502 def find (self , sub : str , start : SupportsIndex | None = ..., end : SupportsIndex | None = ..., / ) -> int : ...
503+ @overload
504+ def format (self : LiteralString , * args : LiteralString , ** kwargs : LiteralString ) -> LiteralString : ...
505+ @overload
490506 def format (self , * args : object , ** kwargs : object ) -> str : ...
491507 def format_map (self , mapping : _FormatMapMapping , / ) -> str : ...
492508 def index (self , sub : str , start : SupportsIndex | None = ..., end : SupportsIndex | None = ..., / ) -> int : ...
@@ -502,34 +518,98 @@ class str(Sequence[str]):
502518 def isspace (self ) -> bool : ...
503519 def istitle (self ) -> bool : ...
504520 def isupper (self ) -> bool : ...
521+ @overload
522+ def join (self : LiteralString , iterable : Iterable [LiteralString ], / ) -> LiteralString : ...
523+ @overload
505524 def join (self , iterable : Iterable [str ], / ) -> str : ... # type: ignore[misc]
525+ @overload
526+ def ljust (self : LiteralString , width : SupportsIndex , fillchar : LiteralString = " " , / ) -> LiteralString : ...
527+ @overload
506528 def ljust (self , width : SupportsIndex , fillchar : str = " " , / ) -> str : ... # type: ignore[misc]
529+ @overload
530+ def lower (self : LiteralString ) -> LiteralString : ...
531+ @overload
507532 def lower (self ) -> str : ... # type: ignore[misc]
533+ @overload
534+ def lstrip (self : LiteralString , chars : LiteralString | None = None , / ) -> LiteralString : ...
535+ @overload
508536 def lstrip (self , chars : str | None = None , / ) -> str : ... # type: ignore[misc]
537+ @overload
538+ def partition (self : LiteralString , sep : LiteralString , / ) -> tuple [LiteralString , LiteralString , LiteralString ]: ...
539+ @overload
509540 def partition (self , sep : str , / ) -> tuple [str , str , str ]: ... # type: ignore[misc]
510541 if sys .version_info >= (3 , 13 ):
542+ @overload
543+ def replace (
544+ self : LiteralString , old : LiteralString , new : LiteralString , / , count : SupportsIndex = - 1
545+ ) -> LiteralString : ...
546+ @overload
511547 def replace (self , old : str , new : str , / , count : SupportsIndex = - 1 ) -> str : ... # type: ignore[misc]
512548 else :
549+ @overload
550+ def replace (
551+ self : LiteralString , old : LiteralString , new : LiteralString , count : SupportsIndex = - 1 , /
552+ ) -> LiteralString : ...
553+ @overload
513554 def replace (self , old : str , new : str , count : SupportsIndex = - 1 , / ) -> str : ... # type: ignore[misc]
514555
556+ @overload
557+ def removeprefix (self : LiteralString , prefix : LiteralString , / ) -> LiteralString : ...
558+ @overload
515559 def removeprefix (self , prefix : str , / ) -> str : ... # type: ignore[misc]
560+ @overload
561+ def removesuffix (self : LiteralString , suffix : LiteralString , / ) -> LiteralString : ...
562+ @overload
516563 def removesuffix (self , suffix : str , / ) -> str : ... # type: ignore[misc]
517564 def rfind (self , sub : str , start : SupportsIndex | None = ..., end : SupportsIndex | None = ..., / ) -> int : ...
518565 def rindex (self , sub : str , start : SupportsIndex | None = ..., end : SupportsIndex | None = ..., / ) -> int : ...
566+ @overload
567+ def rjust (self : LiteralString , width : SupportsIndex , fillchar : LiteralString = " " , / ) -> LiteralString : ...
568+ @overload
519569 def rjust (self , width : SupportsIndex , fillchar : str = " " , / ) -> str : ... # type: ignore[misc]
570+ @overload
571+ def rpartition (self : LiteralString , sep : LiteralString , / ) -> tuple [LiteralString , LiteralString , LiteralString ]: ...
572+ @overload
520573 def rpartition (self , sep : str , / ) -> tuple [str , str , str ]: ... # type: ignore[misc]
574+ @overload
575+ def rsplit (self : LiteralString , sep : LiteralString | None = None , maxsplit : SupportsIndex = - 1 ) -> list [LiteralString ]: ...
576+ @overload
521577 def rsplit (self , sep : str | None = None , maxsplit : SupportsIndex = - 1 ) -> list [str ]: ... # type: ignore[misc]
578+ @overload
579+ def rstrip (self : LiteralString , chars : LiteralString | None = None , / ) -> LiteralString : ...
580+ @overload
522581 def rstrip (self , chars : str | None = None , / ) -> str : ... # type: ignore[misc]
582+ @overload
583+ def split (self : LiteralString , sep : LiteralString | None = None , maxsplit : SupportsIndex = - 1 ) -> list [LiteralString ]: ...
584+ @overload
523585 def split (self , sep : str | None = None , maxsplit : SupportsIndex = - 1 ) -> list [str ]: ... # type: ignore[misc]
586+ @overload
587+ def splitlines (self : LiteralString , keepends : bool = False ) -> list [LiteralString ]: ...
588+ @overload
524589 def splitlines (self , keepends : bool = False ) -> list [str ]: ... # type: ignore[misc]
525590 def startswith (
526591 self , prefix : str | tuple [str , ...], start : SupportsIndex | None = ..., end : SupportsIndex | None = ..., /
527592 ) -> bool : ...
593+ @overload
594+ def strip (self : LiteralString , chars : LiteralString | None = None , / ) -> LiteralString : ...
595+ @overload
528596 def strip (self , chars : str | None = None , / ) -> str : ... # type: ignore[misc]
597+ @overload
598+ def swapcase (self : LiteralString ) -> LiteralString : ...
599+ @overload
529600 def swapcase (self ) -> str : ... # type: ignore[misc]
601+ @overload
602+ def title (self : LiteralString ) -> LiteralString : ...
603+ @overload
530604 def title (self ) -> str : ... # type: ignore[misc]
531605 def translate (self , table : _TranslateTable , / ) -> str : ...
606+ @overload
607+ def upper (self : LiteralString ) -> LiteralString : ...
608+ @overload
532609 def upper (self ) -> str : ... # type: ignore[misc]
610+ @overload
611+ def zfill (self : LiteralString , width : SupportsIndex , / ) -> LiteralString : ...
612+ @overload
533613 def zfill (self , width : SupportsIndex , / ) -> str : ... # type: ignore[misc]
534614 @staticmethod
535615 @overload
@@ -540,21 +620,39 @@ class str(Sequence[str]):
540620 @staticmethod
541621 @overload
542622 def maketrans (x : str , y : str , z : str , / ) -> dict [int , int | None ]: ...
623+ @overload
624+ def __add__ (self : LiteralString , value : LiteralString , / ) -> LiteralString : ...
625+ @overload
543626 def __add__ (self , value : str , / ) -> str : ... # type: ignore[misc]
544627 # Incompatible with Sequence.__contains__
545628 def __contains__ (self , key : str , / ) -> bool : ... # type: ignore[override]
546629 def __eq__ (self , value : object , / ) -> bool : ...
547630 def __ge__ (self , value : str , / ) -> bool : ...
548- def __getitem__ (self , key : SupportsIndex | slice , / ) -> str : ...
631+ @overload
632+ def __getitem__ (self : LiteralString , key : SupportsIndex | slice , / ) -> LiteralString : ...
633+ @overload
634+ def __getitem__ (self , key : SupportsIndex | slice , / ) -> str : ... # type: ignore[misc]
549635 def __gt__ (self , value : str , / ) -> bool : ...
550636 def __hash__ (self ) -> int : ...
637+ @overload
638+ def __iter__ (self : LiteralString ) -> Iterator [LiteralString ]: ...
639+ @overload
551640 def __iter__ (self ) -> Iterator [str ]: ... # type: ignore[misc]
552641 def __le__ (self , value : str , / ) -> bool : ...
553642 def __len__ (self ) -> int : ...
554643 def __lt__ (self , value : str , / ) -> bool : ...
644+ @overload
645+ def __mod__ (self : LiteralString , value : LiteralString | tuple [LiteralString , ...], / ) -> LiteralString : ...
646+ @overload
555647 def __mod__ (self , value : Any , / ) -> str : ...
648+ @overload
649+ def __mul__ (self : LiteralString , value : SupportsIndex , / ) -> LiteralString : ...
650+ @overload
556651 def __mul__ (self , value : SupportsIndex , / ) -> str : ... # type: ignore[misc]
557652 def __ne__ (self , value : object , / ) -> bool : ...
653+ @overload
654+ def __rmul__ (self : LiteralString , value : SupportsIndex , / ) -> LiteralString : ...
655+ @overload
558656 def __rmul__ (self , value : SupportsIndex , / ) -> str : ... # type: ignore[misc]
559657 def __getnewargs__ (self ) -> tuple [str ]: ...
560658 def __format__ (self , format_spec : str , / ) -> str : ...
@@ -923,8 +1021,7 @@ class slice(Generic[_StartT_co, _StopT_co, _StepT_co]):
9231021
9241022 def indices (self , len : SupportsIndex , / ) -> tuple [int , int , int ]: ...
9251023
926- # Making this a disjoint_base upsets pyright
927- # @disjoint_base
1024+ @disjoint_base
9281025class tuple (Sequence [_T_co ]):
9291026 def __new__ (cls , iterable : Iterable [_T_co ] = ..., / ) -> Self : ...
9301027 def __len__ (self ) -> int : ...
@@ -1209,7 +1306,7 @@ class frozenset(AbstractSet[_T_co]):
12091306 def __class_getitem__ (cls , item : Any , / ) -> GenericAlias : ...
12101307
12111308@disjoint_base
1212- class enumerate (Iterator [ tuple [ int , _T ] ]):
1309+ class enumerate (Generic [ _T ]):
12131310 def __new__ (cls , iterable : Iterable [_T ], start : int = 0 ) -> Self : ...
12141311 def __iter__ (self ) -> Self : ...
12151312 def __next__ (self ) -> tuple [int , _T ]: ...
@@ -1266,10 +1363,8 @@ class property:
12661363 def __set__ (self , instance : Any , value : Any , / ) -> None : ...
12671364 def __delete__ (self , instance : Any , / ) -> None : ...
12681365
1269- # This class does not exist at runtime, but stubtest complains if it's marked as
1270- # @type_check_only because it has an alias that does exist at runtime. See mypy#19568.
1271- # @type_check_only
12721366@final
1367+ @type_check_only
12731368class _NotImplementedType (Any ):
12741369 __call__ : None
12751370
@@ -1405,7 +1500,7 @@ else:
14051500exit : _sitebuiltins .Quitter
14061501
14071502@disjoint_base
1408- class filter (Iterator [_T ]):
1503+ class filter (Generic [_T ]):
14091504 @overload
14101505 def __new__ (cls , function : None , iterable : Iterable [_T | None ], / ) -> Self : ...
14111506 @overload
@@ -1469,7 +1564,7 @@ license: _sitebuiltins._Printer
14691564
14701565def locals () -> dict [str , Any ]: ...
14711566@disjoint_base
1472- class map (Iterator [_S ]):
1567+ class map (Generic [_S ]):
14731568 # 3.14 adds `strict` argument.
14741569 if sys .version_info >= (3 , 14 ):
14751570 @overload
@@ -1776,7 +1871,7 @@ def pow(base: _SupportsSomeKindOfPow, exp: complex, mod: None = None) -> complex
17761871quit : _sitebuiltins .Quitter
17771872
17781873@disjoint_base
1779- class reversed (Iterator [_T ]):
1874+ class reversed (Generic [_T ]):
17801875 @overload
17811876 def __new__ (cls , sequence : Reversible [_T ], / ) -> Iterator [_T ]: ... # type: ignore[misc]
17821877 @overload
@@ -1827,7 +1922,7 @@ _SupportsSumNoDefaultT = TypeVar("_SupportsSumNoDefaultT", bound=_SupportsSumWit
18271922# without creating many false-positive errors (see #7578).
18281923# Instead, we special-case the most common examples of this: bool and literal integers.
18291924@overload
1830- def sum (iterable : Iterable [bool ], / , start : int = 0 ) -> int : ...
1925+ def sum (iterable : Iterable [bool | _LiteralInteger ], / , start : int = 0 ) -> int : ...
18311926@overload
18321927def sum (iterable : Iterable [_SupportsSumNoDefaultT ], / ) -> _SupportsSumNoDefaultT | Literal [0 ]: ...
18331928@overload
@@ -1840,7 +1935,7 @@ def vars(object: type, /) -> types.MappingProxyType[str, Any]: ...
18401935@overload
18411936def vars (object : Any = ..., / ) -> dict [str , Any ]: ...
18421937@disjoint_base
1843- class zip (Iterator [_T_co ]):
1938+ class zip (Generic [_T_co ]):
18441939 if sys .version_info >= (3 , 10 ):
18451940 @overload
18461941 def __new__ (cls , * , strict : bool = ...) -> zip [Any ]: ...
0 commit comments