Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
3b230041
Commit
3b230041
authored
Feb 01, 2017
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #29354: Fixed inspect.getargs() for parameters which are cell
variables.
parent
8e21cc3c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
4 deletions
+42
-4
Lib/inspect.py
Lib/inspect.py
+5
-2
Lib/test/test_inspect.py
Lib/test/test_inspect.py
+34
-2
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/inspect.py
View file @
3b230041
...
...
@@ -769,8 +769,11 @@ def getargs(co):
if
opname
in
(
'UNPACK_TUPLE'
,
'UNPACK_SEQUENCE'
):
remain
.
append
(
value
)
count
.
append
(
value
)
elif
opname
==
'STORE_FAST'
:
stack
.
append
(
names
[
value
])
elif
opname
in
(
'STORE_FAST'
,
'STORE_DEREF'
):
if
opname
==
'STORE_FAST'
:
stack
.
append
(
names
[
value
])
else
:
stack
.
append
(
co
.
co_cellvars
[
value
])
# Special case for sublists of length 1: def foo((bar))
# doesn't generate the UNPACK_TUPLE bytecode, so if
...
...
Lib/test/test_inspect.py
View file @
3b230041
...
...
@@ -502,6 +502,15 @@ class TestClassesAndFunctions(unittest.TestCase):
'g'
,
'h'
,
(
3
,
(
4
,
(
5
,))),
'(a, b, c, d=3, (e, (f,))=(4, (5,)), *g, **h)'
)
def
spam_deref
(
a
,
b
,
c
,
d
=
3
,
(
e
,
(
f
,))
=
(
4
,
(
5
,)),
*
g
,
**
h
):
def
eggs
():
return
a
+
b
+
c
+
d
+
e
+
f
+
g
+
h
return
eggs
self
.
assertArgSpecEquals
(
spam_deref
,
[
'a'
,
'b'
,
'c'
,
'd'
,
[
'e'
,
[
'f'
]]],
'g'
,
'h'
,
(
3
,
(
4
,
(
5
,))),
'(a, b, c, d=3, (e, (f,))=(4, (5,)), *g, **h)'
)
def
test_getargspec_method
(
self
):
class
A
(
object
):
def
m
(
self
):
...
...
@@ -515,9 +524,15 @@ class TestClassesAndFunctions(unittest.TestCase):
exec
'def sublistOfOne((foo,)): return 1'
self
.
assertArgSpecEquals
(
sublistOfOne
,
[[
'foo'
]])
exec
'def sublistOfOne((foo,)): return (lambda: foo)'
self
.
assertArgSpecEquals
(
sublistOfOne
,
[[
'foo'
]])
exec
'def fakeSublistOfOne((foo)): return 1'
self
.
assertArgSpecEquals
(
fakeSublistOfOne
,
[
'foo'
])
exec
'def sublistOfOne((foo)): return (lambda: foo)'
self
.
assertArgSpecEquals
(
sublistOfOne
,
[
'foo'
])
def
_classify_test
(
self
,
newstyle
):
"""Helper for testing that classify_class_attrs finds a bunch of
...
...
@@ -820,6 +835,23 @@ class TestGetcallargsFunctions(unittest.TestCase):
self
.
assertEqualException
(
f3
,
'1, 2'
)
self
.
assertEqualException
(
f3
,
'1, 2, a=1, b=2'
)
class
TestGetcallargsFunctionsCellVars
(
TestGetcallargsFunctions
):
def
makeCallable
(
self
,
signature
):
"""Create a function that returns its locals(), excluding the
autogenerated '.1', '.2', etc. tuple param names (if any)."""
with
check_py3k_warnings
(
(
"tuple parameter unpacking has been removed"
,
SyntaxWarning
),
quiet
=
True
):
code
=
"""lambda %s: (
(lambda: a+b+c+d+d+e+f+g+h), # make parameters cell vars
dict(i for i in locals().items()
if not is_tuplename(i[0]))
)[1]"""
return
eval
(
code
%
signature
,
{
'is_tuplename'
:
self
.
is_tuplename
})
class
TestGetcallargsMethods
(
TestGetcallargsFunctions
):
def
setUp
(
self
):
...
...
@@ -857,8 +889,8 @@ def test_main():
run_unittest
(
TestDecorators
,
TestRetrievingSourceCode
,
TestOneliners
,
TestBuggyCases
,
TestInterpreterStack
,
TestClassesAndFunctions
,
TestPredicates
,
TestGetcallargsFunctions
,
TestGetcallargs
Method
s
,
TestGetcallargsUnboundMethods
)
TestGetcallargsFunctions
,
TestGetcallargs
FunctionsCellVar
s
,
TestGetcallargs
Methods
,
TestGetcallargs
UnboundMethods
)
if
__name__
==
"__main__"
:
test_main
()
Misc/NEWS
View file @
3b230041
...
...
@@ -26,6 +26,9 @@ Extension Modules
Library
-------
- Issue #29354: Fixed inspect.getargs() for parameters which are cell
variables.
- Issue #29335: Fix subprocess.Popen.wait() when the child process has
exited to a stopped instead of terminated state (ex: when under ptrace).
...
...
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