Skip to content

Commit

Permalink
Python-3.8 PEP570 positional only argument
Browse files Browse the repository at this point in the history
  • Loading branch information
stonebig authored May 11, 2019
1 parent 380db0d commit 248128d
Showing 1 changed file with 37 additions and 17 deletions.
54 changes: 37 additions & 17 deletions IPython/core/interactiveshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,23 +138,43 @@ def removed_co_newlocals(function:types.FunctionType) -> types.FunctionType:
from types import CodeType, FunctionType
CO_NEWLOCALS = 0x0002
code = function.__code__
new_code = CodeType(
code.co_argcount,
code.co_kwonlyargcount,
code.co_nlocals,
code.co_stacksize,
code.co_flags & ~CO_NEWLOCALS,
code.co_code,
code.co_consts,
code.co_names,
code.co_varnames,
code.co_filename,
code.co_name,
code.co_firstlineno,
code.co_lnotab,
code.co_freevars,
code.co_cellvars
)
if sys.version_info > (3,8):
new_code = CodeType(
code.co_argcount,
code.co_posonlyargcount, # Python-3.8 PEP570 positional only argument
code.co_kwonlyargcount,
code.co_nlocals,
code.co_stacksize,
code.co_flags & ~CO_NEWLOCALS,
code.co_code,
code.co_consts,
code.co_names,
code.co_varnames,
code.co_filename,
code.co_name,
code.co_firstlineno,
code.co_lnotab,
code.co_freevars,
code.co_cellvars
)
else:
new_code = CodeType(
code.co_argcount,
code.co_kwonlyargcount,
code.co_nlocals,
code.co_stacksize,
code.co_flags & ~CO_NEWLOCALS,
code.co_code,
code.co_consts,
code.co_names,
code.co_varnames,
code.co_filename,
code.co_name,
code.co_firstlineno,
code.co_lnotab,
code.co_freevars,
code.co_cellvars
)
return FunctionType(new_code, globals(), function.__name__, function.__defaults__)


Expand Down

0 comments on commit 248128d

Please sign in to comment.