@@ -55,7 +55,7 @@ from typing import ( # noqa: Y027
55
55
overload ,
56
56
type_check_only ,
57
57
)
58
- from typing_extensions import Literal , SupportsIndex , TypeAlias , TypeGuard , final
58
+ from typing_extensions import Literal , LiteralString , SupportsIndex , TypeAlias , TypeGuard , final
59
59
60
60
if sys .version_info >= (3 , 9 ):
61
61
from types import GenericAlias
@@ -414,20 +414,38 @@ class str(Sequence[str]):
414
414
def __new__ (cls : type [Self ], object : object = ...) -> Self : ...
415
415
@overload
416
416
def __new__ (cls : type [Self ], object : ReadableBuffer , encoding : str = ..., errors : str = ...) -> Self : ...
417
+ @overload
418
+ def capitalize (self : LiteralString ) -> LiteralString : ...
419
+ @overload
417
420
def capitalize (self ) -> str : ... # type: ignore[misc]
421
+ @overload
422
+ def casefold (self : LiteralString ) -> LiteralString : ...
423
+ @overload
418
424
def casefold (self ) -> str : ... # type: ignore[misc]
425
+ @overload
426
+ def center (self : LiteralString , __width : SupportsIndex , __fillchar : LiteralString = ...) -> LiteralString : ...
427
+ @overload
419
428
def center (self , __width : SupportsIndex , __fillchar : str = ...) -> str : ... # type: ignore[misc]
420
429
def count (self , x : str , __start : SupportsIndex | None = ..., __end : SupportsIndex | None = ...) -> int : ...
421
430
def encode (self , encoding : str = ..., errors : str = ...) -> bytes : ...
422
431
def endswith (
423
432
self , __suffix : str | tuple [str , ...], __start : SupportsIndex | None = ..., __end : SupportsIndex | None = ...
424
433
) -> bool : ...
425
434
if sys .version_info >= (3 , 8 ):
435
+ @overload
436
+ def expandtabs (self : LiteralString , tabsize : SupportsIndex = ...) -> LiteralString : ...
437
+ @overload
426
438
def expandtabs (self , tabsize : SupportsIndex = ...) -> str : ... # type: ignore[misc]
427
439
else :
440
+ @overload
441
+ def expandtabs (self : LiteralString , tabsize : int = ...) -> LiteralString : ...
442
+ @overload
428
443
def expandtabs (self , tabsize : int = ...) -> str : ... # type: ignore[misc]
429
444
430
445
def find (self , __sub : str , __start : SupportsIndex | None = ..., __end : SupportsIndex | None = ...) -> int : ...
446
+ @overload
447
+ def format (self : LiteralString , * args : LiteralString , ** kwargs : LiteralString ) -> LiteralString : ...
448
+ @overload
431
449
def format (self , * args : object , ** kwargs : object ) -> str : ... # type: ignore[misc]
432
450
def format_map (self , map : _FormatMapMapping ) -> str : ...
433
451
def index (self , __sub : str , __start : SupportsIndex | None = ..., __end : SupportsIndex | None = ...) -> int : ...
@@ -443,53 +461,127 @@ class str(Sequence[str]):
443
461
def isspace (self ) -> bool : ...
444
462
def istitle (self ) -> bool : ...
445
463
def isupper (self ) -> bool : ...
464
+ @overload
465
+ def join (self : LiteralString , __iterable : Iterable [LiteralString ]) -> LiteralString : ...
466
+ @overload
446
467
def join (self , __iterable : Iterable [str ]) -> str : ... # type: ignore[misc]
468
+ @overload
469
+ def ljust (self : LiteralString , __width : SupportsIndex , __fillchar : LiteralString = ...) -> LiteralString : ...
470
+ @overload
447
471
def ljust (self , __width : SupportsIndex , __fillchar : str = ...) -> str : ... # type: ignore[misc]
472
+ @overload
473
+ def lower (self : LiteralString ) -> LiteralString : ...
474
+ @overload
448
475
def lower (self ) -> str : ... # type: ignore[misc]
476
+ @overload
477
+ def lstrip (self : LiteralString , __chars : LiteralString | None = ...) -> LiteralString : ...
478
+ @overload
449
479
def lstrip (self , __chars : str | None = ...) -> str : ... # type: ignore[misc]
480
+ @overload
481
+ def partition (self : LiteralString , __sep : LiteralString ) -> tuple [LiteralString , LiteralString , LiteralString ]: ...
482
+ @overload
450
483
def partition (self , __sep : str ) -> tuple [str , str , str ]: ... # type: ignore[misc]
484
+ @overload
485
+ def replace (
486
+ self : LiteralString , __old : LiteralString , __new : LiteralString , __count : SupportsIndex = ...
487
+ ) -> LiteralString : ...
488
+ @overload
451
489
def replace (self , __old : str , __new : str , __count : SupportsIndex = ...) -> str : ... # type: ignore[misc]
452
490
if sys .version_info >= (3 , 9 ):
491
+ @overload
492
+ def removeprefix (self : LiteralString , __prefix : LiteralString ) -> LiteralString : ...
493
+ @overload
453
494
def removeprefix (self , __prefix : str ) -> str : ... # type: ignore[misc]
495
+ @overload
496
+ def removesuffix (self : LiteralString , __suffix : LiteralString ) -> LiteralString : ...
497
+ @overload
454
498
def removesuffix (self , __suffix : str ) -> str : ... # type: ignore[misc]
455
499
456
500
def rfind (self , __sub : str , __start : SupportsIndex | None = ..., __end : SupportsIndex | None = ...) -> int : ...
457
501
def rindex (self , __sub : str , __start : SupportsIndex | None = ..., __end : SupportsIndex | None = ...) -> int : ...
502
+ @overload
503
+ def rjust (self : LiteralString , __width : SupportsIndex , __fillchar : LiteralString = ...) -> LiteralString : ...
504
+ @overload
458
505
def rjust (self , __width : SupportsIndex , __fillchar : str = ...) -> str : ... # type: ignore[misc]
506
+ @overload
507
+ def rpartition (self : LiteralString , __sep : LiteralString ) -> tuple [LiteralString , LiteralString , LiteralString ]: ...
508
+ @overload
459
509
def rpartition (self , __sep : str ) -> tuple [str , str , str ]: ... # type: ignore[misc]
510
+ @overload
511
+ def rsplit (self : LiteralString , sep : LiteralString | None = ..., maxsplit : SupportsIndex = ...) -> list [LiteralString ]: ...
512
+ @overload
460
513
def rsplit (self , sep : str | None = ..., maxsplit : SupportsIndex = ...) -> list [str ]: ... # type: ignore[misc]
514
+ @overload
515
+ def rstrip (self : LiteralString , __chars : LiteralString | None = ...) -> LiteralString : ...
516
+ @overload
461
517
def rstrip (self , __chars : str | None = ...) -> str : ... # type: ignore[misc]
518
+ @overload
519
+ def split (self : LiteralString , sep : LiteralString | None = ..., maxsplit : SupportsIndex = ...) -> list [LiteralString ]: ...
520
+ @overload
462
521
def split (self , sep : str | None = ..., maxsplit : SupportsIndex = ...) -> list [str ]: ... # type: ignore[misc]
522
+ @overload
523
+ def splitlines (self : LiteralString , keepends : bool = ...) -> list [LiteralString ]: ...
524
+ @overload
463
525
def splitlines (self , keepends : bool = ...) -> list [str ]: ... # type: ignore[misc]
464
526
def startswith (
465
527
self , __prefix : str | tuple [str , ...], __start : SupportsIndex | None = ..., __end : SupportsIndex | None = ...
466
528
) -> bool : ...
529
+ @overload
530
+ def strip (self : LiteralString , __chars : LiteralString | None = ...) -> LiteralString : ...
531
+ @overload
467
532
def strip (self , __chars : str | None = ...) -> str : ... # type: ignore[misc]
533
+ @overload
534
+ def swapcase (self : LiteralString ) -> LiteralString : ...
535
+ @overload
468
536
def swapcase (self ) -> str : ... # type: ignore[misc]
537
+ @overload
538
+ def title (self : LiteralString ) -> LiteralString : ...
539
+ @overload
469
540
def title (self ) -> str : ... # type: ignore[misc]
470
541
def translate (self , __table : _TranslateTable ) -> str : ...
542
+ @overload
543
+ def upper (self : LiteralString ) -> LiteralString : ...
544
+ @overload
471
545
def upper (self ) -> str : ... # type: ignore[misc]
546
+ @overload
547
+ def zfill (self : LiteralString , __width : SupportsIndex ) -> LiteralString : ...
548
+ @overload
472
549
def zfill (self , __width : SupportsIndex ) -> str : ... # type: ignore[misc]
473
550
@staticmethod
474
551
@overload
475
552
def maketrans (__x : dict [int , _T ] | dict [str , _T ] | dict [str | int , _T ]) -> dict [int , _T ]: ...
476
553
@staticmethod
477
554
@overload
478
555
def maketrans (__x : str , __y : str , __z : str | None = ...) -> dict [int , int | None ]: ...
556
+ @overload
557
+ def __add__ (self : LiteralString , __s : LiteralString ) -> LiteralString : ...
558
+ @overload
479
559
def __add__ (self , __s : str ) -> str : ... # type: ignore[misc]
480
560
# Incompatible with Sequence.__contains__
481
561
def __contains__ (self , __o : str ) -> bool : ... # type: ignore[override]
482
562
def __eq__ (self , __x : object ) -> bool : ...
483
563
def __ge__ (self , __x : str ) -> bool : ...
484
564
def __getitem__ (self , __i : SupportsIndex | slice ) -> str : ...
485
565
def __gt__ (self , __x : str ) -> bool : ...
566
+ @overload
567
+ def __iter__ (self : LiteralString ) -> Iterator [LiteralString ]: ...
568
+ @overload
486
569
def __iter__ (self ) -> Iterator [str ]: ... # type: ignore[misc]
487
570
def __le__ (self , __x : str ) -> bool : ...
488
571
def __len__ (self ) -> int : ...
489
572
def __lt__ (self , __x : str ) -> bool : ...
573
+ @overload
574
+ def __mod__ (self : LiteralString , __x : LiteralString | tuple [LiteralString , ...]) -> LiteralString : ...
575
+ @overload
490
576
def __mod__ (self , __x : Any ) -> str : ... # type: ignore[misc]
577
+ @overload
578
+ def __mul__ (self : LiteralString , __n : SupportsIndex ) -> LiteralString : ...
579
+ @overload
491
580
def __mul__ (self , __n : SupportsIndex ) -> str : ... # type: ignore[misc]
492
581
def __ne__ (self , __x : object ) -> bool : ...
582
+ @overload
583
+ def __rmul__ (self : LiteralString , __n : SupportsIndex ) -> LiteralString : ...
584
+ @overload
493
585
def __rmul__ (self , __n : SupportsIndex ) -> str : ... # type: ignore[misc]
494
586
def __getnewargs__ (self ) -> tuple [str ]: ...
495
587
0 commit comments