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 larry
Recipients georg.brandl, larry, ncoghlan, serhiy.storchaka, yselivanov, zach.ware
Date 2014-02-07.06:44:52
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1391755498.83.0.0178215568774.issue20530@psf.upfronthosting.co.za>
In-reply-to
Content
Thanks for noticing the "(/)", that's fixed.

Yes, the signature for type() was wrong.  type() can accept either one parameter or three parameters--in other words, it uses optional groups.  And we can't represent optional groups in an inspect.Signature signature in 3.4.  And I assert that it's better to not have a signature than to have a wrong signature.  So I've removed it.

I'm interested in your "other minor stuff".  I'll try and leave the patch alone this time :)

If you apply diff #2, you'll have a failure in test_inspect.  This is because there's a bug in inspect.Signature that it would take too long to fix, and I have to leave right now-ish.  I changed the tests so they expect the correct results, but they get the wrong results at the moment.
Hopefully we can fix this really quickly.

--

Yuri: This change uncovered a lurking bug in inspect.Signature that I'm hoping you can fix.  I could probably figure it out given enough time but I won't have time to look at it for about 24 hours.

Now that type() doesn't have a signature, I have discovered that some of the logic in Signature is wrong.  

   class C(type): pass
   print(str(inspect.signature(C)))

The signature of that *should* be the same as type().  But inspect.signature() reports the signature as '()'.

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?)

I *think* what it should do is: simply try the first entry in the MRO.  If that has a signature, return it.  If it doesn't have a signature, inspect.Signature should raise ValueError.

I also *think* that all the code after this comment:
    # No '__text_signature__' was found for the 'obj' class.
should be removed.  If C doesn't define its own __new__ or __init__, and its base class doesn't have __call__, then the signature of C *is* the signature of its base class.  If inspect.Signature can't read that signature, then it can't return a signature for C.
History
Date User Action Args
2014-02-07 06:45:02larrysetrecipients: + larry, georg.brandl, ncoghlan, zach.ware, serhiy.storchaka, yselivanov
2014-02-07 06:44:58larrysetmessageid: <1391755498.83.0.0178215568774.issue20530@psf.upfronthosting.co.za>
2014-02-07 06:44:58larrylinkissue20530 messages
2014-02-07 06:44:58larrycreate