1
1
import sys
2
+ from collections import deque
2
3
from collections .abc import Iterable
3
- from typing import TextIO , overload
4
+ from io import TextIOWrapper
5
+ from typing import Literal , Protocol , overload , type_check_only
4
6
from typing_extensions import Self , deprecated
5
7
6
8
__all__ = ["shlex" , "split" , "quote" , "join" ]
7
9
10
+ @type_check_only
11
+ class _ShlexInstream (Protocol ):
12
+ def read (self , size : Literal [1 ], / ) -> str : ...
13
+ def readline (self ) -> object : ...
14
+ def close (self ) -> object : ...
15
+
8
16
if sys .version_info >= (3 , 12 ):
9
- def split (s : str | TextIO , comments : bool = False , posix : bool = True ) -> list [str ]: ...
17
+ def split (s : str | _ShlexInstream , comments : bool = False , posix : bool = True ) -> list [str ]: ...
10
18
11
19
else :
12
20
@overload
13
- def split (s : str | TextIO , comments : bool = False , posix : bool = True ) -> list [str ]: ...
21
+ def split (s : str | _ShlexInstream , comments : bool = False , posix : bool = True ) -> list [str ]: ...
14
22
@overload
15
23
@deprecated ("Passing None for 's' to shlex.split() is deprecated and will raise an error in Python 3.12." )
16
24
def split (s : None , comments : bool = False , posix : bool = True ) -> list [str ]: ...
17
25
18
26
def join (split_command : Iterable [str ]) -> str : ...
19
27
def quote (s : str ) -> str : ...
20
28
29
+ # TODO: Make generic over infile once PEP 696 is implemented.
21
30
class shlex (Iterable [str ]):
22
31
commenters : str
23
32
wordchars : str
@@ -27,26 +36,27 @@ class shlex(Iterable[str]):
27
36
escapedquotes : str
28
37
whitespace_split : bool
29
38
infile : str | None
30
- instream : TextIO
39
+ instream : _ShlexInstream
31
40
source : str
32
41
debug : int
33
42
lineno : int
34
43
token : str
44
+ filestack : deque [tuple [str | None , _ShlexInstream , int ]]
35
45
eof : str | None
36
46
@property
37
47
def punctuation_chars (self ) -> str : ...
38
48
def __init__ (
39
49
self ,
40
- instream : str | TextIO | None = None ,
50
+ instream : str | _ShlexInstream | None = None ,
41
51
infile : str | None = None ,
42
52
posix : bool = False ,
43
53
punctuation_chars : bool | str = False ,
44
54
) -> None : ...
45
55
def get_token (self ) -> str | None : ...
46
56
def push_token (self , tok : str ) -> None : ...
47
57
def read_token (self ) -> str | None : ...
48
- def sourcehook (self , newfile : str ) -> tuple [str , TextIO ] | None : ...
49
- def push_source (self , newstream : str | TextIO , newfile : str | None = None ) -> None : ...
58
+ def sourcehook (self , newfile : str ) -> tuple [str , TextIOWrapper ] | None : ...
59
+ def push_source (self , newstream : str | _ShlexInstream , newfile : str | None = None ) -> None : ...
50
60
def pop_source (self ) -> None : ...
51
61
def error_leader (self , infile : str | None = None , lineno : int | None = None ) -> str : ...
52
62
def __iter__ (self ) -> Self : ...
0 commit comments