summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_code.py
diff options
context:
space:
mode:
authorPablo Galindo <Pablogsal@gmail.com>2019-04-29 12:36:57 (GMT)
committerGitHub <noreply@github.com>2019-04-29 12:36:57 (GMT)
commit8c77b8cb9188165a123f2512026e3629bf03dc9b (patch)
tree863ea19f5f2c8ec179c32b3d06dc8366859ae26e /Lib/test/test_code.py
parent99fcc616d400cd31af0733c3f8cc93bcc1d32a44 (diff)
downloadcpython-8c77b8cb9188165a123f2512026e3629bf03dc9b.zip
cpython-8c77b8cb9188165a123f2512026e3629bf03dc9b.tar.gz
cpython-8c77b8cb9188165a123f2512026e3629bf03dc9b.tar.bz2
bpo-36540: PEP 570 -- Implementation (GH-12701)
This commit contains the implementation of PEP570: Python positional-only parameters. * Update Grammar/Grammar with new typedarglist and varargslist * Regenerate grammar files * Update and regenerate AST related files * Update code object * Update marshal.c * Update compiler and symtable * Regenerate importlib files * Update callable objects * Implement positional-only args logic in ceval.c * Regenerate frozen data * Update standard library to account for positional-only args * Add test file for positional-only args * Update other test files to account for positional-only args * Add News entry * Update inspect module and related tests
Diffstat (limited to 'Lib/test/test_code.py')
-rw-r--r--Lib/test/test_code.py28
1 files changed, 26 insertions, 2 deletions
diff --git a/Lib/test/test_code.py b/Lib/test/test_code.py
index 55faf4c..e49121e 100644
--- a/Lib/test/test_code.py
+++ b/Lib/test/test_code.py
@@ -9,6 +9,7 @@
>>> dump(f.__code__)
name: f
argcount: 1
+posonlyargcount: 0
kwonlyargcount: 0
names: ()
varnames: ('x', 'g')
@@ -21,6 +22,7 @@ consts: ('None', '<code object g>', "'f.<locals>.g'")
>>> dump(f(4).__code__)
name: g
argcount: 1
+posonlyargcount: 0
kwonlyargcount: 0
names: ()
varnames: ('y',)
@@ -40,6 +42,7 @@ consts: ('None',)
>>> dump(h.__code__)
name: h
argcount: 2
+posonlyargcount: 0
kwonlyargcount: 0
names: ()
varnames: ('x', 'y', 'a', 'b', 'c')
@@ -57,6 +60,7 @@ consts: ('None',)
>>> dump(attrs.__code__)
name: attrs
argcount: 1
+posonlyargcount: 0
kwonlyargcount: 0
names: ('print', 'attr1', 'attr2', 'attr3')
varnames: ('obj',)
@@ -75,6 +79,7 @@ consts: ('None',)
>>> dump(optimize_away.__code__)
name: optimize_away
argcount: 0
+posonlyargcount: 0
kwonlyargcount: 0
names: ()
varnames: ()
@@ -91,6 +96,7 @@ consts: ("'doc string'", 'None')
>>> dump(keywordonly_args.__code__)
name: keywordonly_args
argcount: 2
+posonlyargcount: 0
kwonlyargcount: 1
names: ()
varnames: ('a', 'b', 'k1')
@@ -100,6 +106,23 @@ nlocals: 3
flags: 67
consts: ('None',)
+>>> def posonly_args(a,b,/,c):
+... return a,b,c
+...
+
+>>> dump(posonly_args.__code__)
+name: posonly_args
+argcount: 1
+posonlyargcount: 2
+kwonlyargcount: 0
+names: ()
+varnames: ('a', 'b', 'c')
+cellvars: ()
+freevars: ()
+nlocals: 3
+flags: 67
+consts: ('None',)
+
"""
import inspect
@@ -126,7 +149,8 @@ def consts(t):
def dump(co):
"""Print out a text representation of a code object."""
- for attr in ["name", "argcount", "kwonlyargcount", "names", "varnames",
+ for attr in ["name", "argcount", "posonlyargcount",
+ "kwonlyargcount", "names", "varnames",
"cellvars", "freevars", "nlocals", "flags"]:
print("%s: %s" % (attr, getattr(co, "co_" + attr)))
print("consts:", tuple(consts(co.co_consts)))
@@ -157,7 +181,7 @@ class CodeTest(unittest.TestCase):
def new_code(c):
'''A new code object with a __class__ cell added to freevars'''
return CodeType(
- c.co_argcount, c.co_kwonlyargcount, c.co_nlocals,
+ c.co_argcount, c.co_posonlyargcount, c.co_kwonlyargcount, c.co_nlocals,
c.co_stacksize, c.co_flags, c.co_code, c.co_consts, c.co_names,
c.co_varnames, c.co_filename, c.co_name, c.co_firstlineno,
c.co_lnotab, c.co_freevars + ('__class__',), c.co_cellvars)