[Patches] [ python-Patches-637217 ] inspect.getargspec: None instead of ()

SourceForge.net noreply at sourceforge.net
Sat Jul 10 23:07:48 CEST 2004


Patches item #637217, was opened at 2002-11-12 08:40
Message generated for change (Comment added) made by bcannon
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=637217&group_id=5470

>Category: Library (Lib)
Group: None
>Status: Closed
>Resolution: Rejected
Priority: 5
Submitted By: Nathan Srebro (nati)
Assigned to: Nobody/Anonymous (nobody)
Summary: inspect.getargspec: None instead of ()

Initial Comment:
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)

----------------------------------------------------------------------

>Comment By: Brett Cannon (bcannon)
Date: 2004-07-10 14:07

Message:
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.

----------------------------------------------------------------------

Comment By: Brett Cannon (bcannon)
Date: 2003-05-21 19:27

Message:
Logged In: YES 
user_id=357491

Making this a patch since it has code.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=637217&group_id=5470


More information about the Patches mailing list