16
16
17
17
# Standard Library
18
18
import ast
19
- import collections
20
19
import distutils .errors
21
20
import os .path
22
21
import shutil
38
37
except ImportError :
39
38
cythonize = None
40
39
41
-
42
40
PACKAGE_NAME = "threaded"
43
41
44
42
with open (os .path .join (os .path .dirname (__file__ ), PACKAGE_NAME , "__init__.py" )) as f :
52
50
53
51
54
52
# noinspection PyCallingNonCallable
55
- if cythonize is not None and "win32" != sys . platform :
53
+ if cythonize is not None :
56
54
REQUIRES_OPTIMIZATION = [
57
55
setuptools .Extension ("threaded.class_decorator" , ["threaded/class_decorator.pyx" ]),
58
56
setuptools .Extension ("threaded._base_threaded" , ["threaded/_base_threaded.py" ]),
59
57
setuptools .Extension ("threaded._asynciotask" , ["threaded/_asynciotask.pyx" ]),
60
58
setuptools .Extension ("threaded._threaded" , ["threaded/_threaded.pyx" ]),
61
59
setuptools .Extension ("threaded._threadpooled" , ["threaded/_threadpooled.py" ]),
62
- setuptools . Extension ( "threaded.__init__" , [ "threaded/__init__.pyx" ]),
60
+
63
61
]
62
+ if "win32" != sys .platform :
63
+ # NOTE: Do not make pyx/pxd - it kills windows
64
+ REQUIRES_OPTIMIZATION .append (setuptools .Extension ("threaded.__init__" , ["threaded/__init__.py" ]),)
65
+
64
66
INTERFACES = ["class_decorator.pxd" , "_asynciotask.pxd" , "_threaded.pxd" ]
65
67
66
68
EXT_MODULES = cythonize (
@@ -104,7 +106,7 @@ def run(self):
104
106
shutil .copyfile (src , dst )
105
107
except (
106
108
distutils .errors .DistutilsPlatformError ,
107
- getattr ( globals ()[ "__builtins__" ], " FileNotFoundError" , OSError ) ,
109
+ FileNotFoundError ,
108
110
):
109
111
raise BuildFailed ()
110
112
@@ -127,7 +129,7 @@ def build_extension(self, ext):
127
129
# noinspection PyUnresolvedReferences
128
130
def get_simple_vars_from_src (
129
131
src : str
130
- ) -> "typing.Dict[str, typing.Union[str, bytes, int, float, complex, list, set, dict, tuple, None]]" :
132
+ ) -> "typing.Dict[str, typing.Union[str, bytes, int, float, complex, list, set, dict, tuple, None, bool, Ellipsis ]]" :
131
133
"""Get simple (string/number/boolean and None) assigned values from source.
132
134
133
135
:param src: Source code
@@ -139,7 +141,7 @@ def get_simple_vars_from_src(
139
141
str, bytes,
140
142
int, float, complex,
141
143
list, set, dict, tuple,
142
- None,
144
+ None, bool, Ellipsis
143
145
]
144
146
]
145
147
@@ -152,32 +154,33 @@ def get_simple_vars_from_src(
152
154
153
155
>>> string_sample = "a = '1'"
154
156
>>> get_simple_vars_from_src(string_sample)
155
- OrderedDict([( 'a', '1')])
157
+ { 'a': '1'}
156
158
157
159
>>> int_sample = "b = 1"
158
160
>>> get_simple_vars_from_src(int_sample)
159
- OrderedDict([( 'b', 1)])
161
+ { 'b': 1}
160
162
161
163
>>> list_sample = "c = [u'1', b'1', 1, 1.0, 1j, None]"
162
164
>>> result = get_simple_vars_from_src(list_sample)
163
- >>> result == collections.OrderedDict(
164
- ... [('c', [u'1', b'1', 1, 1.0, 1j, None])]
165
- ... )
165
+ >>> result == {'c': [u'1', b'1', 1, 1.0, 1j, None]}
166
166
True
167
167
168
168
>>> iterable_sample = "d = ([1], {1: 1}, {1})"
169
169
>>> get_simple_vars_from_src(iterable_sample)
170
- OrderedDict([( 'd', ([1], {1: 1}, {1}))])
170
+ { 'd': ([1], {1: 1}, {1})}
171
171
172
172
>>> multiple_assign = "e = f = g = 1"
173
173
>>> get_simple_vars_from_src(multiple_assign)
174
- OrderedDict([( 'e', 1), ( 'f', 1), ( 'g', 1)])
174
+ { 'e': 1, 'f': 1, 'g': 1}
175
175
"""
176
- ast_data = (ast .Str , ast .Num , ast .List , ast .Set , ast .Dict , ast .Tuple , ast .Bytes , ast .NameConstant )
176
+ if sys .version_info [:2 ] < (3 , 8 ):
177
+ ast_data = (ast .Str , ast .Num , ast .List , ast .Set , ast .Dict , ast .Tuple , ast .Bytes , ast .NameConstant , ast .Ellipsis )
178
+ else :
179
+ ast_data = ast .Constant
177
180
178
181
tree = ast .parse (src )
179
182
180
- result = collections . OrderedDict ()
183
+ result = {}
181
184
182
185
for node in ast .iter_child_nodes (tree ):
183
186
if not isinstance (node , ast .Assign ): # We parse assigns only
0 commit comments