@@ -15,6 +15,7 @@ import numpy as np
1515import pandas as pd
1616from pandas import (
1717 DataFrame ,
18+ Index ,
1819 MultiIndex ,
1920 Series ,
2021)
@@ -28,10 +29,12 @@ from pandas._typing import (
2829
2930# The _TS type is what is used for the result of str.split with expand=True
3031_TS = TypeVar ("_TS" , DataFrame , MultiIndex )
32+ # The _TS2 type is what is used for the result of str.split with expand=False
33+ _TS2 = TypeVar ("_TS2" , Series [list [str ]], Index [list [str ]])
3134# The _TM type is what is used for the result of str.match
3235_TM = TypeVar ("_TM" , Series [bool ], np_ndarray_bool )
3336
34- class StringMethods (NoNewAttributesMixin , Generic [T , _TS , _TM ]):
37+ class StringMethods (NoNewAttributesMixin , Generic [T , _TS , _TM , _TS2 ]):
3538 def __init__ (self , data : T ) -> None : ...
3639 def __getitem__ (self , key : slice | int ) -> T : ...
3740 def __iter__ (self ) -> T : ...
@@ -66,12 +69,19 @@ class StringMethods(NoNewAttributesMixin, Generic[T, _TS, _TM]):
6669 ) -> _TS : ...
6770 @overload
6871 def split (
69- self , pat : str = ..., * , n : int = ..., expand : bool = ..., regex : bool = ...
70- ) -> T : ...
72+ self ,
73+ pat : str = ...,
74+ * ,
75+ n : int = ...,
76+ expand : Literal [False ] = ...,
77+ regex : bool = ...,
78+ ) -> _TS2 : ...
7179 @overload
7280 def rsplit (self , pat : str = ..., * , n : int = ..., expand : Literal [True ]) -> _TS : ...
7381 @overload
74- def rsplit (self , pat : str = ..., * , n : int = ..., expand : bool = ...) -> T : ...
82+ def rsplit (
83+ self , pat : str = ..., * , n : int = ..., expand : Literal [False ] = ...
84+ ) -> _TS2 : ...
7585 @overload
7686 def partition (self , sep : str = ...) -> pd .DataFrame : ...
7787 @overload
0 commit comments