Python 3.8: PEP 570 positional only arguments (patch)

This commit is contained in:
Miro Hrončok 2019-05-27 14:04:11 +02:00
parent 25810e08f8
commit dbe539c83b
2 changed files with 100 additions and 0 deletions

97
11720.patch Normal file
View File

@ -0,0 +1,97 @@
From 248128dfaabb33e922b1e36a298fd7ec0c730069 Mon Sep 17 00:00:00 2001
From: stonebig <stonebig34@gmail.com>
Date: Sat, 11 May 2019 14:19:20 +0200
Subject: [PATCH 1/2] Python-3.8 PEP570 positional only argument
---
IPython/core/interactiveshell.py | 54 ++++++++++++++++++++++----------
1 file changed, 37 insertions(+), 17 deletions(-)
diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py
index ce8ceb196c..8cc89e4192 100644
--- a/IPython/core/interactiveshell.py
+++ b/IPython/core/interactiveshell.py
@@ -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__)
From 3b160421894ef3495781a6d76fe0edd0fe44ea2d Mon Sep 17 00:00:00 2001
From: stonebig <stonebig34@gmail.com>
Date: Sat, 11 May 2019 14:31:54 +0200
Subject: [PATCH 2/2] be more precise : >3.8.0a3
---
IPython/core/interactiveshell.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py
index 8cc89e4192..c102b2352d 100644
--- a/IPython/core/interactiveshell.py
+++ b/IPython/core/interactiveshell.py
@@ -138,7 +138,7 @@ def removed_co_newlocals(function:types.FunctionType) -> types.FunctionType:
from types import CodeType, FunctionType
CO_NEWLOCALS = 0x0002
code = function.__code__
- if sys.version_info > (3,8):
+ if sys.version_info > (3, 8, 0, 'alpha', 3):
new_code = CodeType(
code.co_argcount,
code.co_posonlyargcount, # Python-3.8 PEP570 positional only argument

View File

@ -13,6 +13,9 @@ License: (BSD and MIT and Python) and GPLv2+
URL: http://ipython.org/
Source0: %pypi_source
# Python 3.8: PEP 570 positional only arguments
Patch1: https://github.com/ipython/ipython/pull/11720.patch
BuildArch: noarch
BuildRequires: python3-devel