Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
0a9f0bd0
Commit
0a9f0bd0
authored
Sep 10, 2011
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
let func.__code__.varnames include local variable names
parent
36780b2a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
21 deletions
+45
-21
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+5
-5
tests/run/cyfunction.pyx
tests/run/cyfunction.pyx
+40
-16
No files found.
Cython/Compiler/ExprNodes.py
View file @
0a9f0bd0
...
...
@@ -5256,7 +5256,7 @@ class CodeObjectNode(ExprNode):
# Create a PyCodeObject for a CyFunction instance.
#
# def_node DefNode the Python function node
# varnames TupleNode a tuple with all variable names
# varnames TupleNode a tuple with all
local
variable names
subexprs
=
[
'varnames'
]
is_temp
=
False
...
...
@@ -5268,12 +5268,12 @@ class CodeObjectNode(ExprNode):
args
.
append
(
def_node
.
star_arg
)
if
def_node
.
starstar_arg
:
args
.
append
(
def_node
.
starstar_arg
)
# FIXME: lacks non-args !
local_vars
=
def_node
.
local_scope
.
var_entries
self
.
varnames
=
TupleNode
(
def_node
.
pos
,
args
=
[
IdentifierStringNode
(
arg
.
pos
,
unicode_value
=
arg
.
name
,
value
=
StringEncoding
.
BytesLiteral
(
arg
.
name
.
utf8encode
()))
for
arg
in
args
],
for
arg
in
args
+
local_vars
],
is_temp
=
0
,
is_literal
=
1
)
...
...
@@ -5299,8 +5299,8 @@ class CodeObjectNode(ExprNode):
len
(
self
.
varnames
.
args
),
# nlocals
Naming
.
empty_bytes
,
# code
Naming
.
empty_tuple
,
# consts
Naming
.
empty_tuple
,
# names (FIXME
: all local non-args!
)
self
.
varnames
.
result
(),
# varnames
Naming
.
empty_tuple
,
# names (FIXME)
self
.
varnames
.
result
(),
# varnames
Naming
.
empty_tuple
,
# freevars (FIXME)
Naming
.
empty_tuple
,
# cellvars (FIXME)
file_path_const
,
# filename
...
...
tests/run/cyfunction.pyx
View file @
0a9f0bd0
...
...
@@ -93,17 +93,25 @@ def codeof(func):
else
:
return
func
.
func_code
def
cy_no_arg
():
pass
def
cy_one_arg
(
a
):
pass
def
cy_two_args
(
x
,
b
):
pass
def
cy_default_args
(
x
=
1
,
b
=
2
):
pass
def
cy_no_arg
():
l
=
0.5
m
=
1
def
cy_one_arg
(
a
):
l
=
0.5
m
=
1
def
cy_two_args
(
x
,
b
):
l
=
0.5
m
=
1
def
cy_default_args
(
x
=
1
,
b
=
2
):
l
=
0.5
m
=
1
def
test_code
():
"""
>>> def no_arg():
pass
>>> def one_arg(a):
pass
>>> def two_args(x, b):
pass
>>> def default_args(x=1, b=2):
pass
>>> def no_arg():
l = m = 1
>>> def one_arg(a):
l = m = 1
>>> def two_args(x, b):
l = m = 1
>>> def default_args(x=1, b=2):
l = m = 1
>>> codeof(no_arg).co_argcount
0
...
...
@@ -113,10 +121,14 @@ def test_code():
no_arg
>>> print(codeof(cy_no_arg).co_name)
cy_no_arg
>>> codeof(no_arg).co_
var
names
>>> codeof(no_arg).co_names
()
>>> codeof(cy_no_arg).co_
var
names
>>> codeof(cy_no_arg).co_names
()
>>> codeof(no_arg).co_varnames
('l', 'm')
>>> codeof(cy_no_arg).co_varnames
('l', 'm')
>>> codeof(one_arg).co_argcount
1
...
...
@@ -126,26 +138,38 @@ def test_code():
one_arg
>>> print(codeof(cy_one_arg).co_name)
cy_one_arg
>>> codeof(one_arg).co_names
()
>>> codeof(cy_one_arg).co_names
()
>>> codeof(one_arg).co_varnames
('a',)
('a',
'l', 'm'
)
>>> codeof(cy_one_arg).co_varnames
('a',)
('a',
'l', 'm'
)
>>> codeof(two_args).co_argcount
2
>>> codeof(cy_two_args).co_argcount
2
>>> codeof(two_args).co_names
()
>>> codeof(cy_two_args).co_names
()
>>> codeof(two_args).co_varnames
('x', 'b')
('x', 'b'
, 'l', 'm'
)
>>> codeof(cy_two_args).co_varnames
('x', 'b')
('x', 'b'
, 'l', 'm'
)
>>> codeof(default_args).co_argcount
2
>>> codeof(cy_default_args).co_argcount
2
>>> codeof(default_args).co_names
()
>>> codeof(cy_default_args).co_names
()
>>> codeof(default_args).co_varnames
('x', 'b')
('x', 'b'
, 'l', 'm'
)
>>> codeof(cy_default_args).co_varnames
('x', 'b')
('x', 'b'
, 'l', 'm'
)
"""
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment