summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_code.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2006-10-27 23:31:49 (GMT)
committerGuido van Rossum <guido@python.org>2006-10-27 23:31:49 (GMT)
commit4f72a78684bbfcdc43ceeabb240ceee54706c4b0 (patch)
tree743c27c5125dcef580cffe77395fe97bedf40d5f /Lib/test/test_code.py
parentfc2a0a8e3cb1d40fd965576060c28c8bd2ea1ad5 (diff)
downloadcpython-4f72a78684bbfcdc43ceeabb240ceee54706c4b0.zip
cpython-4f72a78684bbfcdc43ceeabb240ceee54706c4b0.tar.gz
cpython-4f72a78684bbfcdc43ceeabb240ceee54706c4b0.tar.bz2
Jiwon Seo's PEP 3102 implementation.
See SF#1549670. The compiler package has not yet been updated.
Diffstat (limited to 'Lib/test/test_code.py')
-rw-r--r--Lib/test/test_code.py26
1 files changed, 24 insertions, 2 deletions
diff --git a/Lib/test/test_code.py b/Lib/test/test_code.py
index 4e68638..7ee7dcd 100644
--- a/Lib/test/test_code.py
+++ b/Lib/test/test_code.py
@@ -9,6 +9,7 @@
>>> dump(f.func_code)
name: f
argcount: 1
+kwonlyargcount: 0
names: ()
varnames: ('x', 'g')
cellvars: ('x',)
@@ -20,6 +21,7 @@ consts: ('None', '<code object g>')
>>> dump(f(4).func_code)
name: g
argcount: 1
+kwonlyargcount: 0
names: ()
varnames: ('y',)
cellvars: ()
@@ -34,9 +36,11 @@ consts: ('None',)
... c = a * b
... return c
...
+
>>> dump(h.func_code)
name: h
argcount: 2
+kwonlyargcount: 0
names: ()
varnames: ('x', 'y', 'a', 'b', 'c')
cellvars: ()
@@ -53,6 +57,7 @@ consts: ('None',)
>>> dump(attrs.func_code)
name: attrs
argcount: 1
+kwonlyargcount: 0
names: ('attr1', 'attr2', 'attr3')
varnames: ('obj',)
cellvars: ()
@@ -70,6 +75,7 @@ consts: ('None',)
>>> dump(optimize_away.func_code)
name: optimize_away
argcount: 0
+kwonlyargcount: 0
names: ()
varnames: ()
cellvars: ()
@@ -78,6 +84,22 @@ nlocals: 0
flags: 67
consts: ("'doc string'", 'None')
+>>> def keywordonly_args(a,b,*,k1):
+... return a,b,k1
+...
+
+>>> dump(keywordonly_args.func_code)
+name: keywordonly_args
+argcount: 2
+kwonlyargcount: 1
+names: ()
+varnames: ('a', 'b', 'k1')
+cellvars: ()
+freevars: ()
+nlocals: 3
+flags: 67
+consts: ('None',)
+
"""
def consts(t):
@@ -91,8 +113,8 @@ def consts(t):
def dump(co):
"""Print out a text representation of a code object."""
- for attr in ["name", "argcount", "names", "varnames", "cellvars",
- "freevars", "nlocals", "flags"]:
+ for attr in ["name", "argcount", "kwonlyargcount", "names", "varnames",
+ "cellvars", "freevars", "nlocals", "flags"]:
print "%s: %s" % (attr, getattr(co, "co_" + attr))
print "consts:", tuple(consts(co.co_consts))