@@ -53,9 +53,10 @@ from typing import ( # noqa: Y022
53
53
overload ,
54
54
type_check_only ,
55
55
)
56
- from typing_extensions import ( # type: ignore
56
+ from typing_extensions import (
57
57
Concatenate ,
58
58
Literal ,
59
+ LiteralString ,
59
60
ParamSpec ,
60
61
Self ,
61
62
SupportsIndex ,
@@ -432,21 +433,39 @@ class str(Sequence[str]):
432
433
def __new__ (cls , object : object = ...) -> Self : ...
433
434
@overload
434
435
def __new__ (cls , object : ReadableBuffer , encoding : str = ..., errors : str = ...) -> Self : ...
436
+ @overload
437
+ def capitalize (self : LiteralString ) -> LiteralString : ...
438
+ @overload
435
439
def capitalize (self ) -> str : ... # type: ignore[misc]
440
+ @overload
441
+ def casefold (self : LiteralString ) -> LiteralString : ...
442
+ @overload
436
443
def casefold (self ) -> str : ... # type: ignore[misc]
444
+ @overload
445
+ def center (self : LiteralString , __width : SupportsIndex , __fillchar : LiteralString = " " ) -> LiteralString : ...
446
+ @overload
437
447
def center (self , __width : SupportsIndex , __fillchar : str = " " ) -> str : ... # type: ignore[misc]
438
448
def count (self , x : str , __start : SupportsIndex | None = ..., __end : SupportsIndex | None = ...) -> int : ...
439
449
def encode (self , encoding : str = "utf-8" , errors : str = "strict" ) -> bytes : ...
440
450
def endswith (
441
451
self , __suffix : str | tuple [str , ...], __start : SupportsIndex | None = ..., __end : SupportsIndex | None = ...
442
452
) -> bool : ...
443
453
if sys .version_info >= (3 , 8 ):
454
+ @overload
455
+ def expandtabs (self : LiteralString , tabsize : SupportsIndex = 8 ) -> LiteralString : ...
456
+ @overload
444
457
def expandtabs (self , tabsize : SupportsIndex = 8 ) -> str : ... # type: ignore[misc]
445
458
else :
459
+ @overload
460
+ def expandtabs (self : LiteralString , tabsize : int = 8 ) -> LiteralString : ...
461
+ @overload
446
462
def expandtabs (self , tabsize : int = 8 ) -> str : ... # type: ignore[misc]
447
463
448
464
def find (self , __sub : str , __start : SupportsIndex | None = ..., __end : SupportsIndex | None = ...) -> int : ...
449
- def format (self , * args : object , ** kwargs : object ) -> str : ... # type: ignore
465
+ @overload
466
+ def format (self : LiteralString , * args : LiteralString , ** kwargs : LiteralString ) -> LiteralString : ...
467
+ @overload
468
+ def format (self , * args : object , ** kwargs : object ) -> str : ...
450
469
def format_map (self , map : _FormatMapMapping ) -> str : ...
451
470
def index (self , __sub : str , __start : SupportsIndex | None = ..., __end : SupportsIndex | None = ...) -> int : ...
452
471
def isalnum (self ) -> bool : ...
@@ -461,32 +480,91 @@ class str(Sequence[str]):
461
480
def isspace (self ) -> bool : ...
462
481
def istitle (self ) -> bool : ...
463
482
def isupper (self ) -> bool : ...
483
+ @overload
484
+ def join (self : LiteralString , __iterable : Iterable [LiteralString ]) -> LiteralString : ...
485
+ @overload
464
486
def join (self , __iterable : Iterable [str ]) -> str : ... # type: ignore[misc]
487
+ @overload
488
+ def ljust (self : LiteralString , __width : SupportsIndex , __fillchar : LiteralString = " " ) -> LiteralString : ...
489
+ @overload
465
490
def ljust (self , __width : SupportsIndex , __fillchar : str = " " ) -> str : ... # type: ignore[misc]
491
+ @overload
492
+ def lower (self : LiteralString ) -> LiteralString : ...
493
+ @overload
466
494
def lower (self ) -> str : ... # type: ignore[misc]
495
+ @overload
496
+ def lstrip (self : LiteralString , __chars : LiteralString | None = None ) -> LiteralString : ...
497
+ @overload
467
498
def lstrip (self , __chars : str | None = None ) -> str : ... # type: ignore[misc]
499
+ @overload
500
+ def partition (self : LiteralString , __sep : LiteralString ) -> tuple [LiteralString , LiteralString , LiteralString ]: ...
501
+ @overload
468
502
def partition (self , __sep : str ) -> tuple [str , str , str ]: ... # type: ignore[misc]
503
+ @overload
504
+ def replace (
505
+ self : LiteralString , __old : LiteralString , __new : LiteralString , __count : SupportsIndex = - 1
506
+ ) -> LiteralString : ...
507
+ @overload
469
508
def replace (self , __old : str , __new : str , __count : SupportsIndex = - 1 ) -> str : ... # type: ignore[misc]
470
509
if sys .version_info >= (3 , 9 ):
510
+ @overload
511
+ def removeprefix (self : LiteralString , __prefix : LiteralString ) -> LiteralString : ...
512
+ @overload
471
513
def removeprefix (self , __prefix : str ) -> str : ... # type: ignore[misc]
514
+ @overload
515
+ def removesuffix (self : LiteralString , __suffix : LiteralString ) -> LiteralString : ...
516
+ @overload
472
517
def removesuffix (self , __suffix : str ) -> str : ... # type: ignore[misc]
473
518
474
519
def rfind (self , __sub : str , __start : SupportsIndex | None = ..., __end : SupportsIndex | None = ...) -> int : ...
475
520
def rindex (self , __sub : str , __start : SupportsIndex | None = ..., __end : SupportsIndex | None = ...) -> int : ...
521
+ @overload
522
+ def rjust (self : LiteralString , __width : SupportsIndex , __fillchar : LiteralString = " " ) -> LiteralString : ...
523
+ @overload
476
524
def rjust (self , __width : SupportsIndex , __fillchar : str = " " ) -> str : ... # type: ignore[misc]
525
+ @overload
526
+ def rpartition (self : LiteralString , __sep : LiteralString ) -> tuple [LiteralString , LiteralString , LiteralString ]: ...
527
+ @overload
477
528
def rpartition (self , __sep : str ) -> tuple [str , str , str ]: ... # type: ignore[misc]
529
+ @overload
530
+ def rsplit (self : LiteralString , sep : LiteralString | None = None , maxsplit : SupportsIndex = - 1 ) -> list [LiteralString ]: ...
531
+ @overload
478
532
def rsplit (self , sep : str | None = None , maxsplit : SupportsIndex = - 1 ) -> list [str ]: ... # type: ignore[misc]
533
+ @overload
534
+ def rstrip (self : LiteralString , __chars : LiteralString | None = None ) -> LiteralString : ...
535
+ @overload
479
536
def rstrip (self , __chars : str | None = None ) -> str : ... # type: ignore[misc]
537
+ @overload
538
+ def split (self : LiteralString , sep : LiteralString | None = None , maxsplit : SupportsIndex = - 1 ) -> list [LiteralString ]: ...
539
+ @overload
480
540
def split (self , sep : str | None = None , maxsplit : SupportsIndex = - 1 ) -> list [str ]: ... # type: ignore[misc]
541
+ @overload
542
+ def splitlines (self : LiteralString , keepends : bool = False ) -> list [LiteralString ]: ...
543
+ @overload
481
544
def splitlines (self , keepends : bool = False ) -> list [str ]: ... # type: ignore[misc]
482
545
def startswith (
483
546
self , __prefix : str | tuple [str , ...], __start : SupportsIndex | None = ..., __end : SupportsIndex | None = ...
484
547
) -> bool : ...
548
+ @overload
549
+ def strip (self : LiteralString , __chars : LiteralString | None = None ) -> LiteralString : ...
550
+ @overload
485
551
def strip (self , __chars : str | None = None ) -> str : ... # type: ignore[misc]
552
+ @overload
553
+ def swapcase (self : LiteralString ) -> LiteralString : ...
554
+ @overload
486
555
def swapcase (self ) -> str : ... # type: ignore[misc]
556
+ @overload
557
+ def title (self : LiteralString ) -> LiteralString : ...
558
+ @overload
487
559
def title (self ) -> str : ... # type: ignore[misc]
488
560
def translate (self , __table : _TranslateTable ) -> str : ...
561
+ @overload
562
+ def upper (self : LiteralString ) -> LiteralString : ...
563
+ @overload
489
564
def upper (self ) -> str : ... # type: ignore[misc]
565
+ @overload
566
+ def zfill (self : LiteralString , __width : SupportsIndex ) -> LiteralString : ...
567
+ @overload
490
568
def zfill (self , __width : SupportsIndex ) -> str : ... # type: ignore[misc]
491
569
@staticmethod
492
570
@overload
@@ -497,20 +575,35 @@ class str(Sequence[str]):
497
575
@staticmethod
498
576
@overload
499
577
def maketrans (__x : str , __y : str , __z : str ) -> dict [int , int | None ]: ...
578
+ @overload
579
+ def __add__ (self : LiteralString , __value : LiteralString ) -> LiteralString : ...
580
+ @overload
500
581
def __add__ (self , __value : str ) -> str : ... # type: ignore[misc]
501
582
# Incompatible with Sequence.__contains__
502
583
def __contains__ (self , __key : str ) -> bool : ... # type: ignore[override]
503
584
def __eq__ (self , __value : object ) -> bool : ...
504
585
def __ge__ (self , __value : str ) -> bool : ...
505
586
def __getitem__ (self , __key : SupportsIndex | slice ) -> str : ...
506
587
def __gt__ (self , __value : str ) -> bool : ...
588
+ @overload
589
+ def __iter__ (self : LiteralString ) -> Iterator [LiteralString ]: ...
590
+ @overload
507
591
def __iter__ (self ) -> Iterator [str ]: ... # type: ignore[misc]
508
592
def __le__ (self , __value : str ) -> bool : ...
509
593
def __len__ (self ) -> int : ...
510
594
def __lt__ (self , __value : str ) -> bool : ...
511
- def __mod__ (self , __value : Any ) -> str : ... # type: ignore
595
+ @overload
596
+ def __mod__ (self : LiteralString , __value : LiteralString | tuple [LiteralString , ...]) -> LiteralString : ...
597
+ @overload
598
+ def __mod__ (self , __value : Any ) -> str : ...
599
+ @overload
600
+ def __mul__ (self : LiteralString , __value : SupportsIndex ) -> LiteralString : ...
601
+ @overload
512
602
def __mul__ (self , __value : SupportsIndex ) -> str : ... # type: ignore[misc]
513
603
def __ne__ (self , __value : object ) -> bool : ...
604
+ @overload
605
+ def __rmul__ (self : LiteralString , __value : SupportsIndex ) -> LiteralString : ...
606
+ @overload
514
607
def __rmul__ (self , __value : SupportsIndex ) -> str : ... # type: ignore[misc]
515
608
def __getnewargs__ (self ) -> tuple [str ]: ...
516
609
@@ -1665,11 +1758,11 @@ _SupportsSumNoDefaultT = TypeVar("_SupportsSumNoDefaultT", bound=_SupportsSumWit
1665
1758
# Instead, we special-case the most common examples of this: bool and literal integers.
1666
1759
if sys .version_info >= (3 , 8 ):
1667
1760
@overload
1668
- def sum (__iterable : Iterable [bool ], start : int = 0 ) -> int : ... # type: ignore[misc]
1761
+ def sum (__iterable : Iterable [bool | _LiteralInteger ], start : int = 0 ) -> int : ... # type: ignore[misc]
1669
1762
1670
1763
else :
1671
1764
@overload
1672
- def sum (__iterable : Iterable [bool ], __start : int = 0 ) -> int : ... # type: ignore[misc]
1765
+ def sum (__iterable : Iterable [bool | _LiteralInteger ], __start : int = 0 ) -> int : ... # type: ignore[misc]
1673
1766
1674
1767
@overload
1675
1768
def sum (__iterable : Iterable [_SupportsSumNoDefaultT ]) -> _SupportsSumNoDefaultT | Literal [0 ]: ...
0 commit comments