Show More
@@ -138,43 +138,27 b' def removed_co_newlocals(function:types.FunctionType) -> types.FunctionType:' | |||||
138 | from types import CodeType, FunctionType |
|
138 | from types import CodeType, FunctionType | |
139 | CO_NEWLOCALS = 0x0002 |
|
139 | CO_NEWLOCALS = 0x0002 | |
140 | code = function.__code__ |
|
140 | code = function.__code__ | |
|
141 | new_co_flags = code.co_flags & ~CO_NEWLOCALS | |||
141 | if sys.version_info > (3, 8, 0, 'alpha', 3): |
|
142 | if sys.version_info > (3, 8, 0, 'alpha', 3): | |
142 |
new_code = |
|
143 | new_code = code.replace(co_flags=new_co_flags) | |
143 | code.co_argcount, |
|
|||
144 | code.co_posonlyargcount, # Python-3.8 PEP570 positional only argument |
|
|||
145 | code.co_kwonlyargcount, |
|
|||
146 | code.co_nlocals, |
|
|||
147 | code.co_stacksize, |
|
|||
148 | code.co_flags & ~CO_NEWLOCALS, |
|
|||
149 | code.co_code, |
|
|||
150 | code.co_consts, |
|
|||
151 | code.co_names, |
|
|||
152 | code.co_varnames, |
|
|||
153 | code.co_filename, |
|
|||
154 | code.co_name, |
|
|||
155 | code.co_firstlineno, |
|
|||
156 | code.co_lnotab, |
|
|||
157 | code.co_freevars, |
|
|||
158 | code.co_cellvars |
|
|||
159 | ) |
|
|||
160 | else: |
|
144 | else: | |
161 | new_code = CodeType( |
|
145 | new_code = CodeType( | |
162 | code.co_argcount, |
|
146 | code.co_argcount, | |
163 | code.co_kwonlyargcount, |
|
147 | code.co_kwonlyargcount, | |
164 |
code.co_nlocals, |
|
148 | code.co_nlocals, | |
165 |
code.co_stacksize, |
|
149 | code.co_stacksize, | |
166 |
|
|
150 | new_co_flags, | |
167 |
code.co_code, |
|
151 | code.co_code, | |
168 | code.co_consts, |
|
152 | code.co_consts, | |
169 |
code.co_names, |
|
153 | code.co_names, | |
170 |
code.co_varnames, |
|
154 | code.co_varnames, | |
171 |
code.co_filename, |
|
155 | code.co_filename, | |
172 |
code.co_name, |
|
156 | code.co_name, | |
173 |
code.co_firstlineno, |
|
157 | code.co_firstlineno, | |
174 |
code.co_lnotab, |
|
158 | code.co_lnotab, | |
175 |
code.co_freevars, |
|
159 | code.co_freevars, | |
176 | code.co_cellvars |
|
160 | code.co_cellvars | |
177 |
) |
|
161 | ) | |
178 | return FunctionType(new_code, globals(), function.__name__, function.__defaults__) |
|
162 | return FunctionType(new_code, globals(), function.__name__, function.__defaults__) | |
179 |
|
163 | |||
180 |
|
164 |
General Comments 0
You need to be logged in to leave comments.
Login now