classification
Title: Dead code in py3k inspect module
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.1, Python 3.2
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: Trundle, amaury.forgeotdarc, georg.brandl
Priority: normal Keywords: patch

Created on 2010-08-25 19:13 by Trundle, last changed 2010-10-15 16:07 by georg.brandl. This issue is now closed.

Files
File name Uploaded Description Edit
dead_code_removed.patch Trundle, 2010-08-25 19:13 Patch against branches/py3k that removes the dead code review
Messages (5)
msg114925 - (view) Author: Andreas Stührk (Trundle) * Date: 2010-08-25 19:13
There is some code in the inspect module that is now with the removal of tuple unpacking in arguments in Python 3 no longer needed. The mentioned code does not even work with Python 3 (because ``len(map(...))`` will raise a TypeError).

The attached patch removes the dead code.
msg114958 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2010-08-26 06:50
Indeed, with 3.1:

>>> def f(x, y): pass
...
>>> inspect.formatargspec(inspect.getargspec(f))
TypeError: object of type 'map' has no len()
msg114967 - (view) Author: Andreas Stührk (Trundle) * Date: 2010-08-26 11:49
The correct call is more something like ``inspect.formatargspec(*inspect.getargspec(f))``, which should work for all (Python) functions in Python 3. In Python 2, tuple unpacking was represented using a nested list for the arguments:

>>> def f(x, (y, z)): pass
... 
>>> inspect.getargspec(f).args
['x', ['y', 'z']]

It is impossible to get such a nested list from `getargspec()` now, but if you provide one, you execute the dead code path:

>>> inspect.formatargspec(['x', ['y', 'z']])
TypeError: object of type 'map' has no len()
msg116607 - (view) Author: Andreas Stührk (Trundle) * Date: 2010-09-16 20:31
The documentation about `getargvalues()` and the docstrings of `getargspec()` and friends still mention nested lists for args. Should I update the patch or should I create a new issue?
msg118790 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-10-15 16:07
Fixed both in r85533.  Thanks!
History
Date User Action Args
2010-10-15 16:07:51georg.brandlsetstatus: open -> closed

messages: + msg118790
2010-09-16 20:31:13Trundlesetmessages: + msg116607
2010-08-29 21:47:21georg.brandlsetassignee: georg.brandl

resolution: accepted
nosy: + georg.brandl
2010-08-26 11:49:35Trundlesetmessages: + msg114967
2010-08-26 06:50:10amaury.forgeotdarcsettype: behavior

messages: + msg114958
nosy: + amaury.forgeotdarc
2010-08-25 22:35:29Trundlesettitle: Dead code in pyk inspect module -> Dead code in py3k inspect module
2010-08-25 19:13:41Trundlecreate