@@ -64,6 +64,7 @@ from typing import ( # noqa: Y022
64
64
from typing_extensions import ( # noqa: Y023
65
65
Concatenate ,
66
66
Literal ,
67
+ LiteralString ,
67
68
ParamSpec ,
68
69
Self ,
69
70
TypeAlias ,
@@ -441,16 +442,31 @@ class str(Sequence[str]):
441
442
def __new__ (cls , object : object = ...) -> Self : ...
442
443
@overload
443
444
def __new__ (cls , object : ReadableBuffer , encoding : str = ..., errors : str = ...) -> Self : ...
445
+ @overload
446
+ def capitalize (self : LiteralString ) -> LiteralString : ...
447
+ @overload
444
448
def capitalize (self ) -> str : ... # type: ignore[misc]
449
+ @overload
450
+ def casefold (self : LiteralString ) -> LiteralString : ...
451
+ @overload
445
452
def casefold (self ) -> str : ... # type: ignore[misc]
453
+ @overload
454
+ def center (self : LiteralString , width : SupportsIndex , fillchar : LiteralString = " " , / ) -> LiteralString : ...
455
+ @overload
446
456
def center (self , width : SupportsIndex , fillchar : str = " " , / ) -> str : ... # type: ignore[misc]
447
457
def count (self , sub : str , start : SupportsIndex | None = ..., end : SupportsIndex | None = ..., / ) -> int : ...
448
458
def encode (self , encoding : str = "utf-8" , errors : str = "strict" ) -> bytes : ...
449
459
def endswith (
450
460
self , suffix : str | tuple [str , ...], start : SupportsIndex | None = ..., end : SupportsIndex | None = ..., /
451
461
) -> bool : ...
462
+ @overload
463
+ def expandtabs (self : LiteralString , tabsize : SupportsIndex = 8 ) -> LiteralString : ...
464
+ @overload
452
465
def expandtabs (self , tabsize : SupportsIndex = 8 ) -> str : ... # type: ignore[misc]
453
466
def find (self , sub : str , start : SupportsIndex | None = ..., end : SupportsIndex | None = ..., / ) -> int : ...
467
+ @overload
468
+ def format (self : LiteralString , * args : LiteralString , ** kwargs : LiteralString ) -> LiteralString : ...
469
+ @overload
454
470
def format (self , * args : object , ** kwargs : object ) -> str : ...
455
471
def format_map (self , mapping : _FormatMapMapping , / ) -> str : ...
456
472
def index (self , sub : str , start : SupportsIndex | None = ..., end : SupportsIndex | None = ..., / ) -> int : ...
@@ -466,35 +482,99 @@ class str(Sequence[str]):
466
482
def isspace (self ) -> bool : ...
467
483
def istitle (self ) -> bool : ...
468
484
def isupper (self ) -> bool : ...
485
+ @overload
486
+ def join (self : LiteralString , iterable : Iterable [LiteralString ], / ) -> LiteralString : ...
487
+ @overload
469
488
def join (self , iterable : Iterable [str ], / ) -> str : ... # type: ignore[misc]
489
+ @overload
490
+ def ljust (self : LiteralString , width : SupportsIndex , fillchar : LiteralString = " " , / ) -> LiteralString : ...
491
+ @overload
470
492
def ljust (self , width : SupportsIndex , fillchar : str = " " , / ) -> str : ... # type: ignore[misc]
493
+ @overload
494
+ def lower (self : LiteralString ) -> LiteralString : ...
495
+ @overload
471
496
def lower (self ) -> str : ... # type: ignore[misc]
497
+ @overload
498
+ def lstrip (self : LiteralString , chars : LiteralString | None = None , / ) -> LiteralString : ...
499
+ @overload
472
500
def lstrip (self , chars : str | None = None , / ) -> str : ... # type: ignore[misc]
501
+ @overload
502
+ def partition (self : LiteralString , sep : LiteralString , / ) -> tuple [LiteralString , LiteralString , LiteralString ]: ...
503
+ @overload
473
504
def partition (self , sep : str , / ) -> tuple [str , str , str ]: ... # type: ignore[misc]
474
505
if sys .version_info >= (3 , 13 ):
506
+ @overload
507
+ def replace (
508
+ self : LiteralString , old : LiteralString , new : LiteralString , / , count : SupportsIndex = - 1
509
+ ) -> LiteralString : ...
510
+ @overload
475
511
def replace (self , old : str , new : str , / , count : SupportsIndex = - 1 ) -> str : ... # type: ignore[misc]
476
512
else :
513
+ @overload
514
+ def replace (
515
+ self : LiteralString , old : LiteralString , new : LiteralString , count : SupportsIndex = - 1 , /
516
+ ) -> LiteralString : ...
517
+ @overload
477
518
def replace (self , old : str , new : str , count : SupportsIndex = - 1 , / ) -> str : ... # type: ignore[misc]
478
519
if sys .version_info >= (3 , 9 ):
520
+ @overload
521
+ def removeprefix (self : LiteralString , prefix : LiteralString , / ) -> LiteralString : ...
522
+ @overload
479
523
def removeprefix (self , prefix : str , / ) -> str : ... # type: ignore[misc]
524
+ @overload
525
+ def removesuffix (self : LiteralString , suffix : LiteralString , / ) -> LiteralString : ...
526
+ @overload
480
527
def removesuffix (self , suffix : str , / ) -> str : ... # type: ignore[misc]
481
528
482
529
def rfind (self , sub : str , start : SupportsIndex | None = ..., end : SupportsIndex | None = ..., / ) -> int : ...
483
530
def rindex (self , sub : str , start : SupportsIndex | None = ..., end : SupportsIndex | None = ..., / ) -> int : ...
531
+ @overload
532
+ def rjust (self : LiteralString , width : SupportsIndex , fillchar : LiteralString = " " , / ) -> LiteralString : ...
533
+ @overload
484
534
def rjust (self , width : SupportsIndex , fillchar : str = " " , / ) -> str : ... # type: ignore[misc]
535
+ @overload
536
+ def rpartition (self : LiteralString , sep : LiteralString , / ) -> tuple [LiteralString , LiteralString , LiteralString ]: ...
537
+ @overload
485
538
def rpartition (self , sep : str , / ) -> tuple [str , str , str ]: ... # type: ignore[misc]
539
+ @overload
540
+ def rsplit (self : LiteralString , sep : LiteralString | None = None , maxsplit : SupportsIndex = - 1 ) -> list [LiteralString ]: ...
541
+ @overload
486
542
def rsplit (self , sep : str | None = None , maxsplit : SupportsIndex = - 1 ) -> list [str ]: ... # type: ignore[misc]
543
+ @overload
544
+ def rstrip (self : LiteralString , chars : LiteralString | None = None , / ) -> LiteralString : ...
545
+ @overload
487
546
def rstrip (self , chars : str | None = None , / ) -> str : ... # type: ignore[misc]
547
+ @overload
548
+ def split (self : LiteralString , sep : LiteralString | None = None , maxsplit : SupportsIndex = - 1 ) -> list [LiteralString ]: ...
549
+ @overload
488
550
def split (self , sep : str | None = None , maxsplit : SupportsIndex = - 1 ) -> list [str ]: ... # type: ignore[misc]
551
+ @overload
552
+ def splitlines (self : LiteralString , keepends : bool = False ) -> list [LiteralString ]: ...
553
+ @overload
489
554
def splitlines (self , keepends : bool = False ) -> list [str ]: ... # type: ignore[misc]
490
555
def startswith (
491
556
self , prefix : str | tuple [str , ...], start : SupportsIndex | None = ..., end : SupportsIndex | None = ..., /
492
557
) -> bool : ...
558
+ @overload
559
+ def strip (self : LiteralString , chars : LiteralString | None = None , / ) -> LiteralString : ...
560
+ @overload
493
561
def strip (self , chars : str | None = None , / ) -> str : ... # type: ignore[misc]
562
+ @overload
563
+ def swapcase (self : LiteralString ) -> LiteralString : ...
564
+ @overload
494
565
def swapcase (self ) -> str : ... # type: ignore[misc]
566
+ @overload
567
+ def title (self : LiteralString ) -> LiteralString : ...
568
+ @overload
495
569
def title (self ) -> str : ... # type: ignore[misc]
496
570
def translate (self , table : _TranslateTable , / ) -> str : ...
571
+ @overload
572
+ def upper (self : LiteralString ) -> LiteralString : ...
573
+ @overload
497
574
def upper (self ) -> str : ... # type: ignore[misc]
575
+ @overload
576
+ def zfill (self : LiteralString , width : SupportsIndex , / ) -> LiteralString : ...
577
+ @overload
498
578
def zfill (self , width : SupportsIndex , / ) -> str : ... # type: ignore[misc]
499
579
@staticmethod
500
580
@overload
@@ -505,21 +585,39 @@ class str(Sequence[str]):
505
585
@staticmethod
506
586
@overload
507
587
def maketrans (x : str , y : str , z : str , / ) -> dict [int , int | None ]: ...
588
+ @overload
589
+ def __add__ (self : LiteralString , value : LiteralString , / ) -> LiteralString : ...
590
+ @overload
508
591
def __add__ (self , value : str , / ) -> str : ... # type: ignore[misc]
509
592
# Incompatible with Sequence.__contains__
510
593
def __contains__ (self , key : str , / ) -> bool : ... # type: ignore[override]
511
594
def __eq__ (self , value : object , / ) -> bool : ...
512
595
def __ge__ (self , value : str , / ) -> bool : ...
513
- def __getitem__ (self , key : SupportsIndex | slice , / ) -> str : ...
596
+ @overload
597
+ def __getitem__ (self : LiteralString , key : SupportsIndex | slice , / ) -> LiteralString : ...
598
+ @overload
599
+ def __getitem__ (self , key : SupportsIndex | slice , / ) -> str : ... # type: ignore[misc]
514
600
def __gt__ (self , value : str , / ) -> bool : ...
515
601
def __hash__ (self ) -> int : ...
602
+ @overload
603
+ def __iter__ (self : LiteralString ) -> Iterator [LiteralString ]: ...
604
+ @overload
516
605
def __iter__ (self ) -> Iterator [str ]: ... # type: ignore[misc]
517
606
def __le__ (self , value : str , / ) -> bool : ...
518
607
def __len__ (self ) -> int : ...
519
608
def __lt__ (self , value : str , / ) -> bool : ...
609
+ @overload
610
+ def __mod__ (self : LiteralString , value : LiteralString | tuple [LiteralString , ...], / ) -> LiteralString : ...
611
+ @overload
520
612
def __mod__ (self , value : Any , / ) -> str : ...
613
+ @overload
614
+ def __mul__ (self : LiteralString , value : SupportsIndex , / ) -> LiteralString : ...
615
+ @overload
521
616
def __mul__ (self , value : SupportsIndex , / ) -> str : ... # type: ignore[misc]
522
617
def __ne__ (self , value : object , / ) -> bool : ...
618
+ @overload
619
+ def __rmul__ (self : LiteralString , value : SupportsIndex , / ) -> LiteralString : ...
620
+ @overload
523
621
def __rmul__ (self , value : SupportsIndex , / ) -> str : ... # type: ignore[misc]
524
622
def __getnewargs__ (self ) -> tuple [str ]: ...
525
623
@@ -1130,7 +1228,7 @@ class frozenset(AbstractSet[_T_co]):
1130
1228
if sys .version_info >= (3 , 9 ):
1131
1229
def __class_getitem__ (cls , item : Any , / ) -> GenericAlias : ...
1132
1230
1133
- class enumerate (Iterator [ tuple [ int , _T ] ]):
1231
+ class enumerate (Generic [ _T ]):
1134
1232
def __new__ (cls , iterable : Iterable [_T ], start : int = 0 ) -> Self : ...
1135
1233
def __iter__ (self ) -> Self : ...
1136
1234
def __next__ (self ) -> tuple [int , _T ]: ...
@@ -1324,7 +1422,7 @@ else:
1324
1422
1325
1423
exit : _sitebuiltins .Quitter
1326
1424
1327
- class filter (Iterator [_T ]):
1425
+ class filter (Generic [_T ]):
1328
1426
@overload
1329
1427
def __new__ (cls , function : None , iterable : Iterable [_T | None ], / ) -> Self : ...
1330
1428
@overload
@@ -1389,7 +1487,7 @@ license: _sitebuiltins._Printer
1389
1487
1390
1488
def locals () -> dict [str , Any ]: ...
1391
1489
1392
- class map (Iterator [_S ]):
1490
+ class map (Generic [_S ]):
1393
1491
@overload
1394
1492
def __new__ (cls , func : Callable [[_T1 ], _S ], iterable : Iterable [_T1 ], / ) -> Self : ...
1395
1493
@overload
@@ -1632,7 +1730,7 @@ def pow(base: _SupportsSomeKindOfPow, exp: complex, mod: None = None) -> complex
1632
1730
1633
1731
quit : _sitebuiltins .Quitter
1634
1732
1635
- class reversed (Iterator [_T ]):
1733
+ class reversed (Generic [_T ]):
1636
1734
@overload
1637
1735
def __new__ (cls , sequence : Reversible [_T ], / ) -> Iterator [_T ]: ... # type: ignore[misc]
1638
1736
@overload
@@ -1680,7 +1778,7 @@ _SupportsSumNoDefaultT = TypeVar("_SupportsSumNoDefaultT", bound=_SupportsSumWit
1680
1778
# without creating many false-positive errors (see #7578).
1681
1779
# Instead, we special-case the most common examples of this: bool and literal integers.
1682
1780
@overload
1683
- def sum (iterable : Iterable [bool ], / , start : int = 0 ) -> int : ...
1781
+ def sum (iterable : Iterable [bool | _LiteralInteger ], / , start : int = 0 ) -> int : ...
1684
1782
@overload
1685
1783
def sum (iterable : Iterable [_SupportsSumNoDefaultT ], / ) -> _SupportsSumNoDefaultT | Literal [0 ]: ...
1686
1784
@overload
@@ -1693,7 +1791,7 @@ def vars(object: type, /) -> types.MappingProxyType[str, Any]: ...
1693
1791
@overload
1694
1792
def vars (object : Any = ..., / ) -> dict [str , Any ]: ...
1695
1793
1696
- class zip (Iterator [_T_co ]):
1794
+ class zip (Generic [_T_co ]):
1697
1795
if sys .version_info >= (3 , 10 ):
1698
1796
@overload
1699
1797
def __new__ (cls , * , strict : bool = ...) -> zip [Any ]: ...
0 commit comments