Larry Hastings added the comment:

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.

----------
Added file: 
http://bugs.python.org/file33953/larry.even.newerer.signature.syntax.2.diff

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue20530>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to