1
1
# fmt: off
2
2
import sys
3
3
4
- if sys .version_info >= (3 , 9 ):
5
- from functools import cache
6
- else : # pragma: no cover
7
- from functools import lru_cache
8
-
9
- cache = lru_cache (maxsize = None )
10
-
11
- if sys .version_info >= (3 , 9 ):
12
- from ast import unparse as ast_unparse
13
- else : # pragma: no cover
14
- from astunparse import unparse as _unparse
15
-
16
- def ast_unparse (t ): # type: ignore
17
- return _unparse (t ).strip ("\t \n \" '" )
18
-
19
4
if sys .version_info >= (3 , 12 ):
20
5
from ast import TypeAlias as ast_TypeAlias
21
6
else : # pragma: no cover
@@ -34,33 +19,12 @@ class TypeAliasType:
34
19
class TypeAlias :
35
20
pass
36
21
37
- if sys .version_info >= (3 , 9 ):
38
- from types import GenericAlias
39
- else : # pragma: no cover
40
- from typing import _GenericAlias as GenericAlias
41
-
42
22
if sys .version_info >= (3 , 10 ):
43
23
from types import UnionType # type: ignore
44
24
else : # pragma: no cover
45
25
class UnionType :
46
26
pass
47
27
48
- if sys .version_info >= (3 , 9 ):
49
- removesuffix = str .removesuffix
50
- else : # pragma: no cover
51
- def removesuffix (x : str , suffix : str ):
52
- if x .endswith (suffix ):
53
- x = x [: - len (suffix )]
54
- return x
55
-
56
- if sys .version_info >= (3 , 9 ):
57
- removeprefix = str .removeprefix
58
- else : # pragma: no cover
59
- def removeprefix (x : str , prefix : str ):
60
- if x .startswith (prefix ):
61
- x = x [len (prefix ):]
62
- return x
63
-
64
28
65
29
if (3 , 9 ) <= sys .version_info < (3 , 9 , 8 ) or (3 , 10 ) <= sys .version_info < (3 , 10 , 1 ): # pragma: no cover
66
30
import inspect
@@ -76,53 +40,6 @@ def formatannotation(annotation) -> str:
76
40
else :
77
41
from inspect import formatannotation
78
42
79
- if sys .version_info >= (3 , 9 ):
80
- from argparse import BooleanOptionalAction
81
- else : # pragma: no cover
82
- # https://github.com/python/cpython/pull/27672
83
- from argparse import Action
84
-
85
- class BooleanOptionalAction (Action ): # pragma: no cover
86
- def __init__ (self ,
87
- option_strings ,
88
- dest ,
89
- default = None ,
90
- type = None ,
91
- choices = None ,
92
- required = False ,
93
- help = None ,
94
- metavar = None ):
95
-
96
- _option_strings = []
97
- for option_string in option_strings :
98
- _option_strings .append (option_string )
99
-
100
- if option_string .startswith ('--' ):
101
- option_string = '--no-' + option_string [2 :]
102
- _option_strings .append (option_string )
103
-
104
- if help is not None and default is not None :
105
- help += " (default: %(default)s)"
106
-
107
- super ().__init__ (
108
- option_strings = _option_strings ,
109
- dest = dest ,
110
- nargs = 0 ,
111
- default = default ,
112
- type = type ,
113
- choices = choices ,
114
- required = required ,
115
- help = help ,
116
- metavar = metavar )
117
-
118
- def __call__ (self , parser , namespace , values , option_string = None ):
119
- if option_string in self .option_strings :
120
- setattr (namespace , self .dest , not option_string .startswith ('--no-' ))
121
-
122
- def format_usage (self ):
123
- return ' | ' .join (self .option_strings )
124
-
125
-
126
43
if sys .version_info >= (3 , 10 ):
127
44
from typing import is_typeddict
128
45
else : # pragma: no cover
@@ -134,15 +51,10 @@ def is_typeddict(tp):
134
51
135
52
136
53
__all__ = [
137
- "cache" ,
138
- "ast_unparse" ,
139
54
"ast_TypeAlias" ,
140
55
"TypeAliasType" ,
141
56
"TypeAlias" ,
142
- "GenericAlias" ,
143
57
"UnionType" ,
144
- "removesuffix" ,
145
58
"formatannotation" ,
146
- "BooleanOptionalAction" ,
147
59
"is_typeddict" ,
148
60
]
0 commit comments