@@ -57,6 +57,7 @@ from typing import ( # noqa: Y022
5757from typing_extensions import (
5858 Concatenate ,
5959 Literal ,
60+ LiteralString ,
6061 ParamSpec ,
6162 Self ,
6263 SupportsIndex ,
@@ -444,20 +445,38 @@ class str(Sequence[str]):
444445 def __new__ (cls , object : object = ...) -> Self : ...
445446 @overload
446447 def __new__ (cls , object : ReadableBuffer , encoding : str = ..., errors : str = ...) -> Self : ...
448+ @overload
449+ def capitalize (self : LiteralString ) -> LiteralString : ...
450+ @overload
447451 def capitalize (self ) -> str : ... # type: ignore[misc]
452+ @overload
453+ def casefold (self : LiteralString ) -> LiteralString : ...
454+ @overload
448455 def casefold (self ) -> str : ... # type: ignore[misc]
456+ @overload
457+ def center (self : LiteralString , __width : SupportsIndex , __fillchar : LiteralString = " " ) -> LiteralString : ...
458+ @overload
449459 def center (self , __width : SupportsIndex , __fillchar : str = " " ) -> str : ... # type: ignore[misc]
450460 def count (self , x : str , __start : SupportsIndex | None = ..., __end : SupportsIndex | None = ...) -> int : ...
451461 def encode (self , encoding : str = "utf-8" , errors : str = "strict" ) -> bytes : ...
452462 def endswith (
453463 self , __suffix : str | tuple [str , ...], __start : SupportsIndex | None = ..., __end : SupportsIndex | None = ...
454464 ) -> bool : ...
455465 if sys .version_info >= (3 , 8 ):
466+ @overload
467+ def expandtabs (self : LiteralString , tabsize : SupportsIndex = 8 ) -> LiteralString : ...
468+ @overload
456469 def expandtabs (self , tabsize : SupportsIndex = 8 ) -> str : ... # type: ignore[misc]
457470 else :
471+ @overload
472+ def expandtabs (self : LiteralString , tabsize : int = 8 ) -> LiteralString : ...
473+ @overload
458474 def expandtabs (self , tabsize : int = 8 ) -> str : ... # type: ignore[misc]
459475
460476 def find (self , __sub : str , __start : SupportsIndex | None = ..., __end : SupportsIndex | None = ...) -> int : ...
477+ @overload
478+ def format (self : LiteralString , * args : LiteralString , ** kwargs : LiteralString ) -> LiteralString : ...
479+ @overload
461480 def format (self , * args : object , ** kwargs : object ) -> str : ...
462481 def format_map (self , map : _FormatMapMapping ) -> str : ...
463482 def index (self , __sub : str , __start : SupportsIndex | None = ..., __end : SupportsIndex | None = ...) -> int : ...
@@ -473,32 +492,91 @@ class str(Sequence[str]):
473492 def isspace (self ) -> bool : ...
474493 def istitle (self ) -> bool : ...
475494 def isupper (self ) -> bool : ...
495+ @overload
496+ def join (self : LiteralString , __iterable : Iterable [LiteralString ]) -> LiteralString : ...
497+ @overload
476498 def join (self , __iterable : Iterable [str ]) -> str : ... # type: ignore[misc]
499+ @overload
500+ def ljust (self : LiteralString , __width : SupportsIndex , __fillchar : LiteralString = " " ) -> LiteralString : ...
501+ @overload
477502 def ljust (self , __width : SupportsIndex , __fillchar : str = " " ) -> str : ... # type: ignore[misc]
503+ @overload
504+ def lower (self : LiteralString ) -> LiteralString : ...
505+ @overload
478506 def lower (self ) -> str : ... # type: ignore[misc]
507+ @overload
508+ def lstrip (self : LiteralString , __chars : LiteralString | None = None ) -> LiteralString : ...
509+ @overload
479510 def lstrip (self , __chars : str | None = None ) -> str : ... # type: ignore[misc]
511+ @overload
512+ def partition (self : LiteralString , __sep : LiteralString ) -> tuple [LiteralString , LiteralString , LiteralString ]: ...
513+ @overload
480514 def partition (self , __sep : str ) -> tuple [str , str , str ]: ... # type: ignore[misc]
515+ @overload
516+ def replace (
517+ self : LiteralString , __old : LiteralString , __new : LiteralString , __count : SupportsIndex = - 1
518+ ) -> LiteralString : ...
519+ @overload
481520 def replace (self , __old : str , __new : str , __count : SupportsIndex = - 1 ) -> str : ... # type: ignore[misc]
482521 if sys .version_info >= (3 , 9 ):
522+ @overload
523+ def removeprefix (self : LiteralString , __prefix : LiteralString ) -> LiteralString : ...
524+ @overload
483525 def removeprefix (self , __prefix : str ) -> str : ... # type: ignore[misc]
526+ @overload
527+ def removesuffix (self : LiteralString , __suffix : LiteralString ) -> LiteralString : ...
528+ @overload
484529 def removesuffix (self , __suffix : str ) -> str : ... # type: ignore[misc]
485530
486531 def rfind (self , __sub : str , __start : SupportsIndex | None = ..., __end : SupportsIndex | None = ...) -> int : ...
487532 def rindex (self , __sub : str , __start : SupportsIndex | None = ..., __end : SupportsIndex | None = ...) -> int : ...
533+ @overload
534+ def rjust (self : LiteralString , __width : SupportsIndex , __fillchar : LiteralString = " " ) -> LiteralString : ...
535+ @overload
488536 def rjust (self , __width : SupportsIndex , __fillchar : str = " " ) -> str : ... # type: ignore[misc]
537+ @overload
538+ def rpartition (self : LiteralString , __sep : LiteralString ) -> tuple [LiteralString , LiteralString , LiteralString ]: ...
539+ @overload
489540 def rpartition (self , __sep : str ) -> tuple [str , str , str ]: ... # type: ignore[misc]
541+ @overload
542+ def rsplit (self : LiteralString , sep : LiteralString | None = None , maxsplit : SupportsIndex = - 1 ) -> list [LiteralString ]: ...
543+ @overload
490544 def rsplit (self , sep : str | None = None , maxsplit : SupportsIndex = - 1 ) -> list [str ]: ... # type: ignore[misc]
545+ @overload
546+ def rstrip (self : LiteralString , __chars : LiteralString | None = None ) -> LiteralString : ...
547+ @overload
491548 def rstrip (self , __chars : str | None = None ) -> str : ... # type: ignore[misc]
549+ @overload
550+ def split (self : LiteralString , sep : LiteralString | None = None , maxsplit : SupportsIndex = - 1 ) -> list [LiteralString ]: ...
551+ @overload
492552 def split (self , sep : str | None = None , maxsplit : SupportsIndex = - 1 ) -> list [str ]: ... # type: ignore[misc]
553+ @overload
554+ def splitlines (self : LiteralString , keepends : bool = False ) -> list [LiteralString ]: ...
555+ @overload
493556 def splitlines (self , keepends : bool = False ) -> list [str ]: ... # type: ignore[misc]
494557 def startswith (
495558 self , __prefix : str | tuple [str , ...], __start : SupportsIndex | None = ..., __end : SupportsIndex | None = ...
496559 ) -> bool : ...
560+ @overload
561+ def strip (self : LiteralString , __chars : LiteralString | None = None ) -> LiteralString : ...
562+ @overload
497563 def strip (self , __chars : str | None = None ) -> str : ... # type: ignore[misc]
564+ @overload
565+ def swapcase (self : LiteralString ) -> LiteralString : ...
566+ @overload
498567 def swapcase (self ) -> str : ... # type: ignore[misc]
568+ @overload
569+ def title (self : LiteralString ) -> LiteralString : ...
570+ @overload
499571 def title (self ) -> str : ... # type: ignore[misc]
500572 def translate (self , __table : _TranslateTable ) -> str : ...
573+ @overload
574+ def upper (self : LiteralString ) -> LiteralString : ...
575+ @overload
501576 def upper (self ) -> str : ... # type: ignore[misc]
577+ @overload
578+ def zfill (self : LiteralString , __width : SupportsIndex ) -> LiteralString : ...
579+ @overload
502580 def zfill (self , __width : SupportsIndex ) -> str : ... # type: ignore[misc]
503581 @staticmethod
504582 @overload
@@ -509,6 +587,9 @@ class str(Sequence[str]):
509587 @staticmethod
510588 @overload
511589 def maketrans (__x : str , __y : str , __z : str ) -> dict [int , int | None ]: ...
590+ @overload
591+ def __add__ (self : LiteralString , __value : LiteralString ) -> LiteralString : ...
592+ @overload
512593 def __add__ (self , __value : str ) -> str : ... # type: ignore[misc]
513594 # Incompatible with Sequence.__contains__
514595 def __contains__ (self , __key : str ) -> bool : ... # type: ignore[override]
@@ -517,13 +598,25 @@ class str(Sequence[str]):
517598 def __getitem__ (self , __key : SupportsIndex | slice ) -> str : ...
518599 def __gt__ (self , __value : str ) -> bool : ...
519600 def __hash__ (self ) -> int : ...
601+ @overload
602+ def __iter__ (self : LiteralString ) -> Iterator [LiteralString ]: ...
603+ @overload
520604 def __iter__ (self ) -> Iterator [str ]: ... # type: ignore[misc]
521605 def __le__ (self , __value : str ) -> bool : ...
522606 def __len__ (self ) -> int : ...
523607 def __lt__ (self , __value : str ) -> bool : ...
608+ @overload
609+ def __mod__ (self : LiteralString , __value : LiteralString | tuple [LiteralString , ...]) -> LiteralString : ...
610+ @overload
524611 def __mod__ (self , __value : Any ) -> str : ...
612+ @overload
613+ def __mul__ (self : LiteralString , __value : SupportsIndex ) -> LiteralString : ...
614+ @overload
525615 def __mul__ (self , __value : SupportsIndex ) -> str : ... # type: ignore[misc]
526616 def __ne__ (self , __value : object ) -> bool : ...
617+ @overload
618+ def __rmul__ (self : LiteralString , __value : SupportsIndex ) -> LiteralString : ...
619+ @overload
527620 def __rmul__ (self , __value : SupportsIndex ) -> str : ... # type: ignore[misc]
528621 def __getnewargs__ (self ) -> tuple [str ]: ...
529622
@@ -1702,11 +1795,11 @@ _SupportsSumNoDefaultT = TypeVar("_SupportsSumNoDefaultT", bound=_SupportsSumWit
17021795# Instead, we special-case the most common examples of this: bool and literal integers.
17031796if sys .version_info >= (3 , 8 ):
17041797 @overload
1705- def sum (__iterable : Iterable [bool ], start : int = 0 ) -> int : ... # type: ignore[overload-overlap]
1798+ def sum (__iterable : Iterable [bool | _LiteralInteger ], start : int = 0 ) -> int : ... # type: ignore[overload-overlap]
17061799
17071800else :
17081801 @overload
1709- def sum (__iterable : Iterable [bool ], __start : int = 0 ) -> int : ... # type: ignore[overload-overlap]
1802+ def sum (__iterable : Iterable [bool | _LiteralInteger ], __start : int = 0 ) -> int : ... # type: ignore[overload-overlap]
17101803
17111804@overload
17121805def sum (__iterable : Iterable [_SupportsSumNoDefaultT ]) -> _SupportsSumNoDefaultT | Literal [0 ]: ...
0 commit comments