Yury Selivanov added the comment:

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

----------
Added file: 
http://bugs.python.org/file33964/larry.even.newerer.signature.syntax.3.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