|
7 | 7 | from time import time |
8 | 8 | from copy import copy |
9 | 9 | from functools import partial |
| 10 | +from sys import version_info |
10 | 11 |
|
11 | 12 | from .regutil import register_decorator |
12 | 13 | from .lazyutil import mark_lazy, lazycall, force |
@@ -293,13 +294,24 @@ def rename(f): |
293 | 294 | # that we can use to re-create the code object with the new name. |
294 | 295 | # (This is no worse than what the stdlib's Lib/modulefinder.py already does.) |
295 | 296 | co = f.__code__ |
296 | | - f.__code__ = CodeType(co.co_argcount, co.co_kwonlyargcount, |
297 | | - co.co_nlocals, co.co_stacksize, co.co_flags, |
298 | | - co.co_code, co.co_consts, co.co_names, |
299 | | - co.co_varnames, co.co_filename, |
300 | | - name, |
301 | | - co.co_firstlineno, co.co_lnotab, co.co_freevars, |
302 | | - co.co_cellvars) |
| 297 | + # https://github.com/ipython/ipython/blob/master/IPython/core/interactiveshell.py |
| 298 | + # https://www.python.org/dev/peps/pep-0570/ |
| 299 | + if version_info > (3, 8, 0, 'alpha', 3): |
| 300 | + f.__code__ = CodeType(co.co_argcount, co.co_posonlyargcount, co.co_kwonlyargcount, |
| 301 | + co.co_nlocals, co.co_stacksize, co.co_flags, |
| 302 | + co.co_code, co.co_consts, co.co_names, |
| 303 | + co.co_varnames, co.co_filename, |
| 304 | + name, |
| 305 | + co.co_firstlineno, co.co_lnotab, co.co_freevars, |
| 306 | + co.co_cellvars) |
| 307 | + else: |
| 308 | + f.__code__ = CodeType(co.co_argcount, co.co_kwonlyargcount, |
| 309 | + co.co_nlocals, co.co_stacksize, co.co_flags, |
| 310 | + co.co_code, co.co_consts, co.co_names, |
| 311 | + co.co_varnames, co.co_filename, |
| 312 | + name, |
| 313 | + co.co_firstlineno, co.co_lnotab, co.co_freevars, |
| 314 | + co.co_cellvars) |
303 | 315 | return f |
304 | 316 | return rename |
305 | 317 |
|
|
0 commit comments