@@ -56,6 +56,7 @@ from typing import ( # noqa: Y022
56
56
from typing_extensions import (
57
57
Concatenate ,
58
58
Literal ,
59
+ LiteralString ,
59
60
ParamSpec ,
60
61
Self ,
61
62
SupportsIndex ,
@@ -315,6 +316,7 @@ class int:
315
316
def __float__ (self ) -> float : ...
316
317
def __int__ (self ) -> int : ...
317
318
def __abs__ (self ) -> int : ...
319
+ def __hash__ (self ) -> int : ...
318
320
def __bool__ (self ) -> bool : ...
319
321
def __index__ (self ) -> int : ...
320
322
@@ -378,6 +380,7 @@ class float:
378
380
def __int__ (self ) -> int : ...
379
381
def __float__ (self ) -> float : ...
380
382
def __abs__ (self ) -> float : ...
383
+ def __hash__ (self ) -> int : ...
381
384
def __bool__ (self ) -> bool : ...
382
385
383
386
class complex :
@@ -417,6 +420,7 @@ class complex:
417
420
def __neg__ (self ) -> complex : ...
418
421
def __pos__ (self ) -> complex : ...
419
422
def __abs__ (self ) -> float : ...
423
+ def __hash__ (self ) -> int : ...
420
424
def __bool__ (self ) -> bool : ...
421
425
if sys .version_info >= (3 , 11 ):
422
426
def __complex__ (self ) -> complex : ...
@@ -432,20 +436,38 @@ class str(Sequence[str]):
432
436
def __new__ (cls , object : object = ...) -> Self : ...
433
437
@overload
434
438
def __new__ (cls , object : ReadableBuffer , encoding : str = ..., errors : str = ...) -> Self : ...
439
+ @overload
440
+ def capitalize (self : LiteralString ) -> LiteralString : ...
441
+ @overload
435
442
def capitalize (self ) -> str : ... # type: ignore[misc]
443
+ @overload
444
+ def casefold (self : LiteralString ) -> LiteralString : ...
445
+ @overload
436
446
def casefold (self ) -> str : ... # type: ignore[misc]
447
+ @overload
448
+ def center (self : LiteralString , __width : SupportsIndex , __fillchar : LiteralString = " " ) -> LiteralString : ...
449
+ @overload
437
450
def center (self , __width : SupportsIndex , __fillchar : str = " " ) -> str : ... # type: ignore[misc]
438
451
def count (self , x : str , __start : SupportsIndex | None = ..., __end : SupportsIndex | None = ...) -> int : ...
439
452
def encode (self , encoding : str = "utf-8" , errors : str = "strict" ) -> bytes : ...
440
453
def endswith (
441
454
self , __suffix : str | tuple [str , ...], __start : SupportsIndex | None = ..., __end : SupportsIndex | None = ...
442
455
) -> bool : ...
443
456
if sys .version_info >= (3 , 8 ):
457
+ @overload
458
+ def expandtabs (self : LiteralString , tabsize : SupportsIndex = 8 ) -> LiteralString : ...
459
+ @overload
444
460
def expandtabs (self , tabsize : SupportsIndex = 8 ) -> str : ... # type: ignore[misc]
445
461
else :
462
+ @overload
463
+ def expandtabs (self : LiteralString , tabsize : int = 8 ) -> LiteralString : ...
464
+ @overload
446
465
def expandtabs (self , tabsize : int = 8 ) -> str : ... # type: ignore[misc]
447
466
448
467
def find (self , __sub : str , __start : SupportsIndex | None = ..., __end : SupportsIndex | None = ...) -> int : ...
468
+ @overload
469
+ def format (self : LiteralString , * args : LiteralString , ** kwargs : LiteralString ) -> LiteralString : ...
470
+ @overload
449
471
def format (self , * args : object , ** kwargs : object ) -> str : ...
450
472
def format_map (self , map : _FormatMapMapping ) -> str : ...
451
473
def index (self , __sub : str , __start : SupportsIndex | None = ..., __end : SupportsIndex | None = ...) -> int : ...
@@ -461,32 +483,91 @@ class str(Sequence[str]):
461
483
def isspace (self ) -> bool : ...
462
484
def istitle (self ) -> bool : ...
463
485
def isupper (self ) -> bool : ...
486
+ @overload
487
+ def join (self : LiteralString , __iterable : Iterable [LiteralString ]) -> LiteralString : ...
488
+ @overload
464
489
def join (self , __iterable : Iterable [str ]) -> str : ... # type: ignore[misc]
490
+ @overload
491
+ def ljust (self : LiteralString , __width : SupportsIndex , __fillchar : LiteralString = " " ) -> LiteralString : ...
492
+ @overload
465
493
def ljust (self , __width : SupportsIndex , __fillchar : str = " " ) -> str : ... # type: ignore[misc]
494
+ @overload
495
+ def lower (self : LiteralString ) -> LiteralString : ...
496
+ @overload
466
497
def lower (self ) -> str : ... # type: ignore[misc]
498
+ @overload
499
+ def lstrip (self : LiteralString , __chars : LiteralString | None = None ) -> LiteralString : ...
500
+ @overload
467
501
def lstrip (self , __chars : str | None = None ) -> str : ... # type: ignore[misc]
502
+ @overload
503
+ def partition (self : LiteralString , __sep : LiteralString ) -> tuple [LiteralString , LiteralString , LiteralString ]: ...
504
+ @overload
468
505
def partition (self , __sep : str ) -> tuple [str , str , str ]: ... # type: ignore[misc]
506
+ @overload
507
+ def replace (
508
+ self : LiteralString , __old : LiteralString , __new : LiteralString , __count : SupportsIndex = - 1
509
+ ) -> LiteralString : ...
510
+ @overload
469
511
def replace (self , __old : str , __new : str , __count : SupportsIndex = - 1 ) -> str : ... # type: ignore[misc]
470
512
if sys .version_info >= (3 , 9 ):
513
+ @overload
514
+ def removeprefix (self : LiteralString , __prefix : LiteralString ) -> LiteralString : ...
515
+ @overload
471
516
def removeprefix (self , __prefix : str ) -> str : ... # type: ignore[misc]
517
+ @overload
518
+ def removesuffix (self : LiteralString , __suffix : LiteralString ) -> LiteralString : ...
519
+ @overload
472
520
def removesuffix (self , __suffix : str ) -> str : ... # type: ignore[misc]
473
521
474
522
def rfind (self , __sub : str , __start : SupportsIndex | None = ..., __end : SupportsIndex | None = ...) -> int : ...
475
523
def rindex (self , __sub : str , __start : SupportsIndex | None = ..., __end : SupportsIndex | None = ...) -> int : ...
524
+ @overload
525
+ def rjust (self : LiteralString , __width : SupportsIndex , __fillchar : LiteralString = " " ) -> LiteralString : ...
526
+ @overload
476
527
def rjust (self , __width : SupportsIndex , __fillchar : str = " " ) -> str : ... # type: ignore[misc]
528
+ @overload
529
+ def rpartition (self : LiteralString , __sep : LiteralString ) -> tuple [LiteralString , LiteralString , LiteralString ]: ...
530
+ @overload
477
531
def rpartition (self , __sep : str ) -> tuple [str , str , str ]: ... # type: ignore[misc]
532
+ @overload
533
+ def rsplit (self : LiteralString , sep : LiteralString | None = None , maxsplit : SupportsIndex = - 1 ) -> list [LiteralString ]: ...
534
+ @overload
478
535
def rsplit (self , sep : str | None = None , maxsplit : SupportsIndex = - 1 ) -> list [str ]: ... # type: ignore[misc]
536
+ @overload
537
+ def rstrip (self : LiteralString , __chars : LiteralString | None = None ) -> LiteralString : ...
538
+ @overload
479
539
def rstrip (self , __chars : str | None = None ) -> str : ... # type: ignore[misc]
540
+ @overload
541
+ def split (self : LiteralString , sep : LiteralString | None = None , maxsplit : SupportsIndex = - 1 ) -> list [LiteralString ]: ...
542
+ @overload
480
543
def split (self , sep : str | None = None , maxsplit : SupportsIndex = - 1 ) -> list [str ]: ... # type: ignore[misc]
544
+ @overload
545
+ def splitlines (self : LiteralString , keepends : bool = False ) -> list [LiteralString ]: ...
546
+ @overload
481
547
def splitlines (self , keepends : bool = False ) -> list [str ]: ... # type: ignore[misc]
482
548
def startswith (
483
549
self , __prefix : str | tuple [str , ...], __start : SupportsIndex | None = ..., __end : SupportsIndex | None = ...
484
550
) -> bool : ...
551
+ @overload
552
+ def strip (self : LiteralString , __chars : LiteralString | None = None ) -> LiteralString : ...
553
+ @overload
485
554
def strip (self , __chars : str | None = None ) -> str : ... # type: ignore[misc]
555
+ @overload
556
+ def swapcase (self : LiteralString ) -> LiteralString : ...
557
+ @overload
486
558
def swapcase (self ) -> str : ... # type: ignore[misc]
559
+ @overload
560
+ def title (self : LiteralString ) -> LiteralString : ...
561
+ @overload
487
562
def title (self ) -> str : ... # type: ignore[misc]
488
563
def translate (self , __table : _TranslateTable ) -> str : ...
564
+ @overload
565
+ def upper (self : LiteralString ) -> LiteralString : ...
566
+ @overload
489
567
def upper (self ) -> str : ... # type: ignore[misc]
568
+ @overload
569
+ def zfill (self : LiteralString , __width : SupportsIndex ) -> LiteralString : ...
570
+ @overload
490
571
def zfill (self , __width : SupportsIndex ) -> str : ... # type: ignore[misc]
491
572
@staticmethod
492
573
@overload
@@ -497,20 +578,36 @@ class str(Sequence[str]):
497
578
@staticmethod
498
579
@overload
499
580
def maketrans (__x : str , __y : str , __z : str ) -> dict [int , int | None ]: ...
581
+ @overload
582
+ def __add__ (self : LiteralString , __value : LiteralString ) -> LiteralString : ...
583
+ @overload
500
584
def __add__ (self , __value : str ) -> str : ... # type: ignore[misc]
501
585
# Incompatible with Sequence.__contains__
502
586
def __contains__ (self , __key : str ) -> bool : ... # type: ignore[override]
503
587
def __eq__ (self , __value : object ) -> bool : ...
504
588
def __ge__ (self , __value : str ) -> bool : ...
505
589
def __getitem__ (self , __key : SupportsIndex | slice ) -> str : ...
506
590
def __gt__ (self , __value : str ) -> bool : ...
591
+ def __hash__ (self ) -> int : ...
592
+ @overload
593
+ def __iter__ (self : LiteralString ) -> Iterator [LiteralString ]: ...
594
+ @overload
507
595
def __iter__ (self ) -> Iterator [str ]: ... # type: ignore[misc]
508
596
def __le__ (self , __value : str ) -> bool : ...
509
597
def __len__ (self ) -> int : ...
510
598
def __lt__ (self , __value : str ) -> bool : ...
599
+ @overload
600
+ def __mod__ (self : LiteralString , __value : LiteralString | tuple [LiteralString , ...]) -> LiteralString : ...
601
+ @overload
511
602
def __mod__ (self , __value : Any ) -> str : ...
603
+ @overload
604
+ def __mul__ (self : LiteralString , __value : SupportsIndex ) -> LiteralString : ...
605
+ @overload
512
606
def __mul__ (self , __value : SupportsIndex ) -> str : ... # type: ignore[misc]
513
607
def __ne__ (self , __value : object ) -> bool : ...
608
+ @overload
609
+ def __rmul__ (self : LiteralString , __value : SupportsIndex ) -> LiteralString : ...
610
+ @overload
514
611
def __rmul__ (self , __value : SupportsIndex ) -> str : ... # type: ignore[misc]
515
612
def __getnewargs__ (self ) -> tuple [str ]: ...
516
613
@@ -597,6 +694,7 @@ class bytes(Sequence[int]):
597
694
def maketrans (__frm : ReadableBuffer , __to : ReadableBuffer ) -> bytes : ...
598
695
def __len__ (self ) -> int : ...
599
696
def __iter__ (self ) -> Iterator [int ]: ...
697
+ def __hash__ (self ) -> int : ...
600
698
@overload
601
699
def __getitem__ (self , __key : SupportsIndex ) -> int : ...
602
700
@overload
@@ -1004,7 +1102,13 @@ class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
1004
1102
__hash__ : ClassVar [None ] # type: ignore[assignment]
1005
1103
if sys .version_info >= (3 , 9 ):
1006
1104
def __class_getitem__ (cls , __item : Any ) -> GenericAlias : ...
1105
+ @overload
1106
+ def __or__ (self , __value : Mapping [_KT , _VT ]) -> dict [_KT , _VT ]: ...
1107
+ @overload
1007
1108
def __or__ (self , __value : Mapping [_T1 , _T2 ]) -> dict [_KT | _T1 , _VT | _T2 ]: ...
1109
+ @overload
1110
+ def __ror__ (self , __value : Mapping [_KT , _VT ]) -> dict [_KT , _VT ]: ...
1111
+ @overload
1008
1112
def __ror__ (self , __value : Mapping [_T1 , _T2 ]) -> dict [_KT | _T1 , _VT | _T2 ]: ...
1009
1113
# dict.__ior__ should be kept roughly in line with MutableMapping.update()
1010
1114
@overload # type: ignore[misc]
@@ -1665,11 +1769,11 @@ _SupportsSumNoDefaultT = TypeVar("_SupportsSumNoDefaultT", bound=_SupportsSumWit
1665
1769
# Instead, we special-case the most common examples of this: bool and literal integers.
1666
1770
if sys .version_info >= (3 , 8 ):
1667
1771
@overload
1668
- def sum (__iterable : Iterable [bool ], start : int = 0 ) -> int : ... # type: ignore[misc]
1772
+ def sum (__iterable : Iterable [bool | _LiteralInteger ], start : int = 0 ) -> int : ... # type: ignore[misc]
1669
1773
1670
1774
else :
1671
1775
@overload
1672
- def sum (__iterable : Iterable [bool ], __start : int = 0 ) -> int : ... # type: ignore[misc]
1776
+ def sum (__iterable : Iterable [bool | _LiteralInteger ], __start : int = 0 ) -> int : ... # type: ignore[misc]
1673
1777
1674
1778
@overload
1675
1779
def sum (__iterable : Iterable [_SupportsSumNoDefaultT ]) -> _SupportsSumNoDefaultT | Literal [0 ]: ...
0 commit comments