This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: inspect.getargspec: None instead of ()
Type: Stage:
Components: Library (Lib) Versions:
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: brett.cannon, nati
Priority: normal Keywords: patch

Created on 2002-11-12 16:40 by nati, last changed 2022-04-10 16:05 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
getargspec.py nati, 2002-11-12 16:40 Corrected getargspec (to be replaced in inspect.py)
Messages (3)
msg41632 - (view) Author: Nathan Srebro (nati) Date: 2002-11-12 16:40
When a function has no default arguments, getargspec
(in module inspec) returns a fourth return-value of None:

>>> inspect.getargspec(lambda x:x)
(['x'], None, None, None)

According to the documentation, the fourth return
value, defaults, "is a tuple of default argument
values; if this tuple has n elements, they correspond
to the last n elements listed in args.". This suggests
that if there are no default arguments, an empty tuple
should be returned. This is also more consistent.
Returning None requires special handling in code using
this return value.

Attached is a corrected version of getargspec (a check
for 'defaults is None' is added).

(This bug exists in both 2.2.2 and the current CVS)
msg41633 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2003-05-22 02:27
Logged In: YES 
user_id=357491

Making this a patch since it has code.
msg41634 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2004-07-10 21:07
Logged In: YES 
user_id=357491

I am rejecting the bug itself for the sole reason that it has been this way 
for ages and changing it now might break code.  But having it return 
None instead of () is not that big of a deal: just have the test be ``not 
inspect.gerargspec(lambda x:x)[3]`` instead of specifying you are 
checking for an empty tuple which is just more Pythonic and better 
practice anyway.

I did clarify the docs to say None is returned when there are no default 
arguments.
History
Date User Action Args
2022-04-10 16:05:53adminsetgithub: 37459
2002-11-12 16:40:00naticreate