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.

Author yselivanov
Recipients georg.brandl, larry, ncoghlan, serhiy.storchaka, yselivanov, zach.ware
Date 2014-02-07.18:55:01
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1391799303.77.0.218671995131.issue20530@psf.upfronthosting.co.za>
In-reply-to
Content
Larry,

I'm attaching a revised version of the patch -- larry.even.newerer.signature.syntax.3.diff.

Changes:

1. test_signature_on_class_without_init was fixed, 
inspect.signature was fixed as well. Now, for

   class Meta(type): pass

"inspect.signature(Meta)" will raise a ValueError.

> I also *think* that all the code after this comment:
>    # No '__text_signature__' was found for the 'obj' class.
> should be removed.

You are right, but I'd prefer to leave that code until 3.5, when we have correct signature for 'type'.

> The reason this happens: inspect.Signature gets to 
> the "for base in mro" case for handling classes.  
> The first base it tries is type(), but type() doesn't 
> have a public signature so it keeps going.  The next 
> class in the MRO is object(), which has a signature 
> of "()", so it uses that.

> It shouldn't keep going!  I'm 99% certain that the first 
> entry in the MRO will always be callable.  (Is it possible 
> to have a type in Python that isn't callable?)

Unfortunately, no, we need to traverse the MRO. See the
"test_signature_on_builtin_class" unit test, for instance.

The way I solved the current bug, is to fixing the code from
traversing the full MRO, to traversing the MRO without the
last item -- 'object' builtin.

2. _strip_non_python_syntax -> _signature_strip_non_python_syntax
Minor fixup, just to have all signature helper functions 
in inspect.py follow one notation.

3. test_strip_non_python_syntax -> was moved to another
test case -- TestSignaturePrivateHelpers

4. I also fixed one thing that Zachary found: unused 's' variable
in the '_signature_fromstr' method.

Here's a quick summary of changes (diff of the diffs,
omitting some changes in tests): 
https://gist.github.com/1st1/8869242
History
Date User Action Args
2014-02-07 18:55:09yselivanovsetrecipients: + yselivanov, georg.brandl, ncoghlan, larry, zach.ware, serhiy.storchaka
2014-02-07 18:55:03yselivanovsetmessageid: <1391799303.77.0.218671995131.issue20530@psf.upfronthosting.co.za>
2014-02-07 18:55:03yselivanovlinkissue20530 messages
2014-02-07 18:55:03yselivanovcreate