@@ -62,6 +62,7 @@ from typing import ( # noqa: Y022
62
62
from typing_extensions import ( # noqa: Y023
63
63
Concatenate ,
64
64
Literal ,
65
+ LiteralString ,
65
66
ParamSpec ,
66
67
Self ,
67
68
TypeAlias ,
@@ -444,16 +445,31 @@ class str(Sequence[str]):
444
445
def __new__ (cls , object : object = ...) -> Self : ...
445
446
@overload
446
447
def __new__ (cls , object : ReadableBuffer , encoding : str = ..., errors : str = ...) -> Self : ...
448
+ @overload
449
+ def capitalize (self : LiteralString ) -> LiteralString : ...
450
+ @overload
447
451
def capitalize (self ) -> str : ... # type: ignore[misc]
452
+ @overload
453
+ def casefold (self : LiteralString ) -> LiteralString : ...
454
+ @overload
448
455
def casefold (self ) -> str : ... # type: ignore[misc]
456
+ @overload
457
+ def center (self : LiteralString , width : SupportsIndex , fillchar : LiteralString = " " , / ) -> LiteralString : ...
458
+ @overload
449
459
def center (self , width : SupportsIndex , fillchar : str = " " , / ) -> str : ... # type: ignore[misc]
450
460
def count (self , sub : str , start : SupportsIndex | None = ..., end : SupportsIndex | None = ..., / ) -> int : ...
451
461
def encode (self , encoding : str = "utf-8" , errors : str = "strict" ) -> bytes : ...
452
462
def endswith (
453
463
self , suffix : str | tuple [str , ...], start : SupportsIndex | None = ..., end : SupportsIndex | None = ..., /
454
464
) -> bool : ...
465
+ @overload
466
+ def expandtabs (self : LiteralString , tabsize : SupportsIndex = 8 ) -> LiteralString : ...
467
+ @overload
455
468
def expandtabs (self , tabsize : SupportsIndex = 8 ) -> str : ... # type: ignore[misc]
456
469
def find (self , sub : str , start : SupportsIndex | None = ..., end : SupportsIndex | None = ..., / ) -> int : ...
470
+ @overload
471
+ def format (self : LiteralString , * args : LiteralString , ** kwargs : LiteralString ) -> LiteralString : ...
472
+ @overload
457
473
def format (self , * args : object , ** kwargs : object ) -> str : ...
458
474
def format_map (self , mapping : _FormatMapMapping , / ) -> str : ...
459
475
def index (self , sub : str , start : SupportsIndex | None = ..., end : SupportsIndex | None = ..., / ) -> int : ...
@@ -469,35 +485,99 @@ class str(Sequence[str]):
469
485
def isspace (self ) -> bool : ...
470
486
def istitle (self ) -> bool : ...
471
487
def isupper (self ) -> bool : ...
488
+ @overload
489
+ def join (self : LiteralString , iterable : Iterable [LiteralString ], / ) -> LiteralString : ...
490
+ @overload
472
491
def join (self , iterable : Iterable [str ], / ) -> str : ... # type: ignore[misc]
492
+ @overload
493
+ def ljust (self : LiteralString , width : SupportsIndex , fillchar : LiteralString = " " , / ) -> LiteralString : ...
494
+ @overload
473
495
def ljust (self , width : SupportsIndex , fillchar : str = " " , / ) -> str : ... # type: ignore[misc]
496
+ @overload
497
+ def lower (self : LiteralString ) -> LiteralString : ...
498
+ @overload
474
499
def lower (self ) -> str : ... # type: ignore[misc]
500
+ @overload
501
+ def lstrip (self : LiteralString , chars : LiteralString | None = None , / ) -> LiteralString : ...
502
+ @overload
475
503
def lstrip (self , chars : str | None = None , / ) -> str : ... # type: ignore[misc]
504
+ @overload
505
+ def partition (self : LiteralString , sep : LiteralString , / ) -> tuple [LiteralString , LiteralString , LiteralString ]: ...
506
+ @overload
476
507
def partition (self , sep : str , / ) -> tuple [str , str , str ]: ... # type: ignore[misc]
477
508
if sys .version_info >= (3 , 13 ):
509
+ @overload
510
+ def replace (
511
+ self : LiteralString , old : LiteralString , new : LiteralString , / , count : SupportsIndex = - 1
512
+ ) -> LiteralString : ...
513
+ @overload
478
514
def replace (self , old : str , new : str , / , count : SupportsIndex = - 1 ) -> str : ... # type: ignore[misc]
479
515
else :
516
+ @overload
517
+ def replace (
518
+ self : LiteralString , old : LiteralString , new : LiteralString , count : SupportsIndex = - 1 , /
519
+ ) -> LiteralString : ...
520
+ @overload
480
521
def replace (self , old : str , new : str , count : SupportsIndex = - 1 , / ) -> str : ... # type: ignore[misc]
481
522
if sys .version_info >= (3 , 9 ):
523
+ @overload
524
+ def removeprefix (self : LiteralString , prefix : LiteralString , / ) -> LiteralString : ...
525
+ @overload
482
526
def removeprefix (self , prefix : str , / ) -> str : ... # type: ignore[misc]
527
+ @overload
528
+ def removesuffix (self : LiteralString , suffix : LiteralString , / ) -> LiteralString : ...
529
+ @overload
483
530
def removesuffix (self , suffix : str , / ) -> str : ... # type: ignore[misc]
484
531
485
532
def rfind (self , sub : str , start : SupportsIndex | None = ..., end : SupportsIndex | None = ..., / ) -> int : ...
486
533
def rindex (self , sub : str , start : SupportsIndex | None = ..., end : SupportsIndex | None = ..., / ) -> int : ...
534
+ @overload
535
+ def rjust (self : LiteralString , width : SupportsIndex , fillchar : LiteralString = " " , / ) -> LiteralString : ...
536
+ @overload
487
537
def rjust (self , width : SupportsIndex , fillchar : str = " " , / ) -> str : ... # type: ignore[misc]
538
+ @overload
539
+ def rpartition (self : LiteralString , sep : LiteralString , / ) -> tuple [LiteralString , LiteralString , LiteralString ]: ...
540
+ @overload
488
541
def rpartition (self , sep : str , / ) -> tuple [str , str , str ]: ... # type: ignore[misc]
542
+ @overload
543
+ def rsplit (self : LiteralString , sep : LiteralString | None = None , maxsplit : SupportsIndex = - 1 ) -> list [LiteralString ]: ...
544
+ @overload
489
545
def rsplit (self , sep : str | None = None , maxsplit : SupportsIndex = - 1 ) -> list [str ]: ... # type: ignore[misc]
546
+ @overload
547
+ def rstrip (self : LiteralString , chars : LiteralString | None = None , / ) -> LiteralString : ...
548
+ @overload
490
549
def rstrip (self , chars : str | None = None , / ) -> str : ... # type: ignore[misc]
550
+ @overload
551
+ def split (self : LiteralString , sep : LiteralString | None = None , maxsplit : SupportsIndex = - 1 ) -> list [LiteralString ]: ...
552
+ @overload
491
553
def split (self , sep : str | None = None , maxsplit : SupportsIndex = - 1 ) -> list [str ]: ... # type: ignore[misc]
554
+ @overload
555
+ def splitlines (self : LiteralString , keepends : bool = False ) -> list [LiteralString ]: ...
556
+ @overload
492
557
def splitlines (self , keepends : bool = False ) -> list [str ]: ... # type: ignore[misc]
493
558
def startswith (
494
559
self , prefix : str | tuple [str , ...], start : SupportsIndex | None = ..., end : SupportsIndex | None = ..., /
495
560
) -> bool : ...
561
+ @overload
562
+ def strip (self : LiteralString , chars : LiteralString | None = None , / ) -> LiteralString : ...
563
+ @overload
496
564
def strip (self , chars : str | None = None , / ) -> str : ... # type: ignore[misc]
565
+ @overload
566
+ def swapcase (self : LiteralString ) -> LiteralString : ...
567
+ @overload
497
568
def swapcase (self ) -> str : ... # type: ignore[misc]
569
+ @overload
570
+ def title (self : LiteralString ) -> LiteralString : ...
571
+ @overload
498
572
def title (self ) -> str : ... # type: ignore[misc]
499
573
def translate (self , table : _TranslateTable , / ) -> str : ...
574
+ @overload
575
+ def upper (self : LiteralString ) -> LiteralString : ...
576
+ @overload
500
577
def upper (self ) -> str : ... # type: ignore[misc]
578
+ @overload
579
+ def zfill (self : LiteralString , width : SupportsIndex , / ) -> LiteralString : ...
580
+ @overload
501
581
def zfill (self , width : SupportsIndex , / ) -> str : ... # type: ignore[misc]
502
582
@staticmethod
503
583
@overload
@@ -508,21 +588,39 @@ class str(Sequence[str]):
508
588
@staticmethod
509
589
@overload
510
590
def maketrans (x : str , y : str , z : str , / ) -> dict [int , int | None ]: ...
591
+ @overload
592
+ def __add__ (self : LiteralString , value : LiteralString , / ) -> LiteralString : ...
593
+ @overload
511
594
def __add__ (self , value : str , / ) -> str : ... # type: ignore[misc]
512
595
# Incompatible with Sequence.__contains__
513
596
def __contains__ (self , key : str , / ) -> bool : ... # type: ignore[override]
514
597
def __eq__ (self , value : object , / ) -> bool : ...
515
598
def __ge__ (self , value : str , / ) -> bool : ...
516
- def __getitem__ (self , key : SupportsIndex | slice , / ) -> str : ...
599
+ @overload
600
+ def __getitem__ (self : LiteralString , key : SupportsIndex | slice , / ) -> LiteralString : ...
601
+ @overload
602
+ def __getitem__ (self , key : SupportsIndex | slice , / ) -> str : ... # type: ignore[misc]
517
603
def __gt__ (self , value : str , / ) -> bool : ...
518
604
def __hash__ (self ) -> int : ...
605
+ @overload
606
+ def __iter__ (self : LiteralString ) -> Iterator [LiteralString ]: ...
607
+ @overload
519
608
def __iter__ (self ) -> Iterator [str ]: ... # type: ignore[misc]
520
609
def __le__ (self , value : str , / ) -> bool : ...
521
610
def __len__ (self ) -> int : ...
522
611
def __lt__ (self , value : str , / ) -> bool : ...
612
+ @overload
613
+ def __mod__ (self : LiteralString , value : LiteralString | tuple [LiteralString , ...], / ) -> LiteralString : ...
614
+ @overload
523
615
def __mod__ (self , value : Any , / ) -> str : ...
616
+ @overload
617
+ def __mul__ (self : LiteralString , value : SupportsIndex , / ) -> LiteralString : ...
618
+ @overload
524
619
def __mul__ (self , value : SupportsIndex , / ) -> str : ... # type: ignore[misc]
525
620
def __ne__ (self , value : object , / ) -> bool : ...
621
+ @overload
622
+ def __rmul__ (self : LiteralString , value : SupportsIndex , / ) -> LiteralString : ...
623
+ @overload
526
624
def __rmul__ (self , value : SupportsIndex , / ) -> str : ... # type: ignore[misc]
527
625
def __getnewargs__ (self ) -> tuple [str ]: ...
528
626
@@ -1149,7 +1247,7 @@ class frozenset(AbstractSet[_T_co]):
1149
1247
if sys .version_info >= (3 , 9 ):
1150
1248
def __class_getitem__ (cls , item : Any , / ) -> GenericAlias : ...
1151
1249
1152
- class enumerate (Iterator [ tuple [ int , _T ] ]):
1250
+ class enumerate (Generic [ _T ]):
1153
1251
def __new__ (cls , iterable : Iterable [_T ], start : int = 0 ) -> Self : ...
1154
1252
def __iter__ (self ) -> Self : ...
1155
1253
def __next__ (self ) -> tuple [int , _T ]: ...
@@ -1343,7 +1441,7 @@ else:
1343
1441
1344
1442
exit : _sitebuiltins .Quitter
1345
1443
1346
- class filter (Iterator [_T ]):
1444
+ class filter (Generic [_T ]):
1347
1445
@overload
1348
1446
def __new__ (cls , function : None , iterable : Iterable [_T | None ], / ) -> Self : ...
1349
1447
@overload
@@ -1408,7 +1506,7 @@ license: _sitebuiltins._Printer
1408
1506
1409
1507
def locals () -> dict [str , Any ]: ...
1410
1508
1411
- class map (Iterator [_S ]):
1509
+ class map (Generic [_S ]):
1412
1510
@overload
1413
1511
def __new__ (cls , func : Callable [[_T1 ], _S ], iterable : Iterable [_T1 ], / ) -> Self : ...
1414
1512
@overload
@@ -1651,7 +1749,7 @@ def pow(base: _SupportsSomeKindOfPow, exp: complex, mod: None = None) -> complex
1651
1749
1652
1750
quit : _sitebuiltins .Quitter
1653
1751
1654
- class reversed (Iterator [_T ]):
1752
+ class reversed (Generic [_T ]):
1655
1753
@overload
1656
1754
def __new__ (cls , sequence : Reversible [_T ], / ) -> Iterator [_T ]: ... # type: ignore[misc]
1657
1755
@overload
@@ -1699,7 +1797,7 @@ _SupportsSumNoDefaultT = TypeVar("_SupportsSumNoDefaultT", bound=_SupportsSumWit
1699
1797
# without creating many false-positive errors (see #7578).
1700
1798
# Instead, we special-case the most common examples of this: bool and literal integers.
1701
1799
@overload
1702
- def sum (iterable : Iterable [bool ], / , start : int = 0 ) -> int : ...
1800
+ def sum (iterable : Iterable [bool | _LiteralInteger ], / , start : int = 0 ) -> int : ...
1703
1801
@overload
1704
1802
def sum (iterable : Iterable [_SupportsSumNoDefaultT ], / ) -> _SupportsSumNoDefaultT | Literal [0 ]: ...
1705
1803
@overload
@@ -1712,7 +1810,7 @@ def vars(object: type, /) -> types.MappingProxyType[str, Any]: ...
1712
1810
@overload
1713
1811
def vars (object : Any = ..., / ) -> dict [str , Any ]: ...
1714
1812
1715
- class zip (Iterator [_T_co ]):
1813
+ class zip (Generic [_T_co ]):
1716
1814
if sys .version_info >= (3 , 10 ):
1717
1815
@overload
1718
1816
def __new__ (cls , * , strict : bool = ...) -> zip [Any ]: ...
0 commit comments