@@ -54,7 +54,7 @@ from typing import ( # noqa: Y022
54
54
overload ,
55
55
type_check_only ,
56
56
)
57
- from typing_extensions import Concatenate , Literal , ParamSpec , Self , SupportsIndex , TypeAlias , TypeGuard , final
57
+ from typing_extensions import Concatenate , Literal , LiteralString , ParamSpec , Self , SupportsIndex , TypeAlias , TypeGuard , final
58
58
59
59
if sys .version_info >= (3 , 9 ):
60
60
from types import GenericAlias
@@ -416,20 +416,38 @@ class str(Sequence[str]):
416
416
def __new__ (cls , object : object = ...) -> Self : ...
417
417
@overload
418
418
def __new__ (cls , object : ReadableBuffer , encoding : str = ..., errors : str = ...) -> Self : ...
419
+ @overload
420
+ def capitalize (self : LiteralString ) -> LiteralString : ...
421
+ @overload
419
422
def capitalize (self ) -> str : ... # type: ignore[misc]
423
+ @overload
424
+ def casefold (self : LiteralString ) -> LiteralString : ...
425
+ @overload
420
426
def casefold (self ) -> str : ... # type: ignore[misc]
427
+ @overload
428
+ def center (self : LiteralString , __width : SupportsIndex , __fillchar : LiteralString = " " ) -> LiteralString : ...
429
+ @overload
421
430
def center (self , __width : SupportsIndex , __fillchar : str = " " ) -> str : ... # type: ignore[misc]
422
431
def count (self , x : str , __start : SupportsIndex | None = ..., __end : SupportsIndex | None = ...) -> int : ...
423
432
def encode (self , encoding : str = "utf-8" , errors : str = "strict" ) -> bytes : ...
424
433
def endswith (
425
434
self , __suffix : str | tuple [str , ...], __start : SupportsIndex | None = ..., __end : SupportsIndex | None = ...
426
435
) -> bool : ...
427
436
if sys .version_info >= (3 , 8 ):
437
+ @overload
438
+ def expandtabs (self : LiteralString , tabsize : SupportsIndex = 8 ) -> LiteralString : ...
439
+ @overload
428
440
def expandtabs (self , tabsize : SupportsIndex = 8 ) -> str : ... # type: ignore[misc]
429
441
else :
442
+ @overload
443
+ def expandtabs (self : LiteralString , tabsize : int = 8 ) -> LiteralString : ...
444
+ @overload
430
445
def expandtabs (self , tabsize : int = 8 ) -> str : ... # type: ignore[misc]
431
446
432
447
def find (self , __sub : str , __start : SupportsIndex | None = ..., __end : SupportsIndex | None = ...) -> int : ...
448
+ @overload
449
+ def format (self : LiteralString , * args : LiteralString , ** kwargs : LiteralString ) -> LiteralString : ...
450
+ @overload
433
451
def format (self , * args : object , ** kwargs : object ) -> str : ...
434
452
def format_map (self , map : _FormatMapMapping ) -> str : ...
435
453
def index (self , __sub : str , __start : SupportsIndex | None = ..., __end : SupportsIndex | None = ...) -> int : ...
@@ -445,32 +463,91 @@ class str(Sequence[str]):
445
463
def isspace (self ) -> bool : ...
446
464
def istitle (self ) -> bool : ...
447
465
def isupper (self ) -> bool : ...
466
+ @overload
467
+ def join (self : LiteralString , __iterable : Iterable [LiteralString ]) -> LiteralString : ...
468
+ @overload
448
469
def join (self , __iterable : Iterable [str ]) -> str : ... # type: ignore[misc]
470
+ @overload
471
+ def ljust (self : LiteralString , __width : SupportsIndex , __fillchar : LiteralString = " " ) -> LiteralString : ...
472
+ @overload
449
473
def ljust (self , __width : SupportsIndex , __fillchar : str = " " ) -> str : ... # type: ignore[misc]
474
+ @overload
475
+ def lower (self : LiteralString ) -> LiteralString : ...
476
+ @overload
450
477
def lower (self ) -> str : ... # type: ignore[misc]
478
+ @overload
479
+ def lstrip (self : LiteralString , __chars : LiteralString | None = None ) -> LiteralString : ...
480
+ @overload
451
481
def lstrip (self , __chars : str | None = None ) -> str : ... # type: ignore[misc]
482
+ @overload
483
+ def partition (self : LiteralString , __sep : LiteralString ) -> tuple [LiteralString , LiteralString , LiteralString ]: ...
484
+ @overload
452
485
def partition (self , __sep : str ) -> tuple [str , str , str ]: ... # type: ignore[misc]
486
+ @overload
487
+ def replace (
488
+ self : LiteralString , __old : LiteralString , __new : LiteralString , __count : SupportsIndex = - 1
489
+ ) -> LiteralString : ...
490
+ @overload
453
491
def replace (self , __old : str , __new : str , __count : SupportsIndex = - 1 ) -> str : ... # type: ignore[misc]
454
492
if sys .version_info >= (3 , 9 ):
493
+ @overload
494
+ def removeprefix (self : LiteralString , __prefix : LiteralString ) -> LiteralString : ...
495
+ @overload
455
496
def removeprefix (self , __prefix : str ) -> str : ... # type: ignore[misc]
497
+ @overload
498
+ def removesuffix (self : LiteralString , __suffix : LiteralString ) -> LiteralString : ...
499
+ @overload
456
500
def removesuffix (self , __suffix : str ) -> str : ... # type: ignore[misc]
457
501
458
502
def rfind (self , __sub : str , __start : SupportsIndex | None = ..., __end : SupportsIndex | None = ...) -> int : ...
459
503
def rindex (self , __sub : str , __start : SupportsIndex | None = ..., __end : SupportsIndex | None = ...) -> int : ...
504
+ @overload
505
+ def rjust (self : LiteralString , __width : SupportsIndex , __fillchar : LiteralString = " " ) -> LiteralString : ...
506
+ @overload
460
507
def rjust (self , __width : SupportsIndex , __fillchar : str = " " ) -> str : ... # type: ignore[misc]
508
+ @overload
509
+ def rpartition (self : LiteralString , __sep : LiteralString ) -> tuple [LiteralString , LiteralString , LiteralString ]: ...
510
+ @overload
461
511
def rpartition (self , __sep : str ) -> tuple [str , str , str ]: ... # type: ignore[misc]
512
+ @overload
513
+ def rsplit (self : LiteralString , sep : LiteralString | None = None , maxsplit : SupportsIndex = - 1 ) -> list [LiteralString ]: ...
514
+ @overload
462
515
def rsplit (self , sep : str | None = None , maxsplit : SupportsIndex = - 1 ) -> list [str ]: ... # type: ignore[misc]
516
+ @overload
517
+ def rstrip (self : LiteralString , __chars : LiteralString | None = None ) -> LiteralString : ...
518
+ @overload
463
519
def rstrip (self , __chars : str | None = None ) -> str : ... # type: ignore[misc]
520
+ @overload
521
+ def split (self : LiteralString , sep : LiteralString | None = None , maxsplit : SupportsIndex = - 1 ) -> list [LiteralString ]: ...
522
+ @overload
464
523
def split (self , sep : str | None = None , maxsplit : SupportsIndex = - 1 ) -> list [str ]: ... # type: ignore[misc]
524
+ @overload
525
+ def splitlines (self : LiteralString , keepends : bool = False ) -> list [LiteralString ]: ...
526
+ @overload
465
527
def splitlines (self , keepends : bool = False ) -> list [str ]: ... # type: ignore[misc]
466
528
def startswith (
467
529
self , __prefix : str | tuple [str , ...], __start : SupportsIndex | None = ..., __end : SupportsIndex | None = ...
468
530
) -> bool : ...
531
+ @overload
532
+ def strip (self : LiteralString , __chars : LiteralString | None = None ) -> LiteralString : ...
533
+ @overload
469
534
def strip (self , __chars : str | None = None ) -> str : ... # type: ignore[misc]
535
+ @overload
536
+ def swapcase (self : LiteralString ) -> LiteralString : ...
537
+ @overload
470
538
def swapcase (self ) -> str : ... # type: ignore[misc]
539
+ @overload
540
+ def title (self : LiteralString ) -> LiteralString : ...
541
+ @overload
471
542
def title (self ) -> str : ... # type: ignore[misc]
472
543
def translate (self , __table : _TranslateTable ) -> str : ...
544
+ @overload
545
+ def upper (self : LiteralString ) -> LiteralString : ...
546
+ @overload
473
547
def upper (self ) -> str : ... # type: ignore[misc]
548
+ @overload
549
+ def zfill (self : LiteralString , __width : SupportsIndex ) -> LiteralString : ...
550
+ @overload
474
551
def zfill (self , __width : SupportsIndex ) -> str : ... # type: ignore[misc]
475
552
@staticmethod
476
553
@overload
@@ -481,20 +558,35 @@ class str(Sequence[str]):
481
558
@staticmethod
482
559
@overload
483
560
def maketrans (__x : str , __y : str , __z : str ) -> dict [int , int | None ]: ...
561
+ @overload
562
+ def __add__ (self : LiteralString , __value : LiteralString ) -> LiteralString : ...
563
+ @overload
484
564
def __add__ (self , __value : str ) -> str : ... # type: ignore[misc]
485
565
# Incompatible with Sequence.__contains__
486
566
def __contains__ (self , __key : str ) -> bool : ... # type: ignore[override]
487
567
def __eq__ (self , __value : object ) -> bool : ...
488
568
def __ge__ (self , __value : str ) -> bool : ...
489
569
def __getitem__ (self , __key : SupportsIndex | slice ) -> str : ...
490
570
def __gt__ (self , __value : str ) -> bool : ...
571
+ @overload
572
+ def __iter__ (self : LiteralString ) -> Iterator [LiteralString ]: ...
573
+ @overload
491
574
def __iter__ (self ) -> Iterator [str ]: ... # type: ignore[misc]
492
575
def __le__ (self , __value : str ) -> bool : ...
493
576
def __len__ (self ) -> int : ...
494
577
def __lt__ (self , __value : str ) -> bool : ...
578
+ @overload
579
+ def __mod__ (self : LiteralString , __value : LiteralString | tuple [LiteralString , ...]) -> LiteralString : ...
580
+ @overload
495
581
def __mod__ (self , __value : Any ) -> str : ...
582
+ @overload
583
+ def __mul__ (self : LiteralString , __value : SupportsIndex ) -> LiteralString : ...
584
+ @overload
496
585
def __mul__ (self , __value : SupportsIndex ) -> str : ... # type: ignore[misc]
497
586
def __ne__ (self , __value : object ) -> bool : ...
587
+ @overload
588
+ def __rmul__ (self : LiteralString , __value : SupportsIndex ) -> LiteralString : ...
589
+ @overload
498
590
def __rmul__ (self , __value : SupportsIndex ) -> str : ... # type: ignore[misc]
499
591
def __getnewargs__ (self ) -> tuple [str ]: ...
500
592
@@ -1638,11 +1730,11 @@ _SupportsSumNoDefaultT = TypeVar("_SupportsSumNoDefaultT", bound=_SupportsSumWit
1638
1730
# Instead, we special-case the most common examples of this: bool and literal integers.
1639
1731
if sys .version_info >= (3 , 8 ):
1640
1732
@overload
1641
- def sum (__iterable : Iterable [bool ], start : int = 0 ) -> int : ... # type: ignore[misc]
1733
+ def sum (__iterable : Iterable [bool | _LiteralInteger ], start : int = 0 ) -> int : ... # type: ignore[misc]
1642
1734
1643
1735
else :
1644
1736
@overload
1645
- def sum (__iterable : Iterable [bool ], __start : int = 0 ) -> int : ... # type: ignore[misc]
1737
+ def sum (__iterable : Iterable [bool | _LiteralInteger ], __start : int = 0 ) -> int : ... # type: ignore[misc]
1646
1738
1647
1739
@overload
1648
1740
def sum (__iterable : Iterable [_SupportsSumNoDefaultT ]) -> _SupportsSumNoDefaultT | Literal [0 ]: ...
@@ -1747,7 +1839,7 @@ def __import__(
1747
1839
name : str ,
1748
1840
globals : Mapping [str , object ] | None = None ,
1749
1841
locals : Mapping [str , object ] | None = None ,
1750
- fromlist : Sequence [str ] = ... ,
1842
+ fromlist : Sequence [str ] = () ,
1751
1843
level : int = 0 ,
1752
1844
) -> types .ModuleType : ...
1753
1845
def __build_class__ (__func : Callable [[], _Cell | Any ], __name : str , * bases : Any , metaclass : Any = ..., ** kwds : Any ) -> Any : ...
0 commit comments