Skip to content

Instantly share code, notes, and snippets.

@1st1
Created February 7, 2014 18:53
Show Gist options
  • Save 1st1/8869242 to your computer and use it in GitHub Desktop.
Save 1st1/8869242 to your computer and use it in GitHub Desktop.
> --- a/Lib/inspect.py Thu Feb 06 22:06:16 2014 -0500
> +++ b/Lib/inspect.py Fri Feb 07 13:41:22 2014 -0500
< +def _strip_non_python_syntax(signature):
---
> +def _signature_strip_non_python_syntax(signature):
> + # Internal helper to convert AC extended signature format
> + # to the standard Python syntax
> +
99a103,106
> - if first_parameter_is_self:
> - s = '(' + s[2:]
> -
> - s = "def foo" + s + ": pass"
101c108
< + _strip_non_python_syntax(s)
---
> + _signature_strip_non_python_syntax(s)
103,107d109
< + first_parameter_is_self = self_parameter == 0
< if first_parameter_is_self:
< s = '(' + s[2:]
<
< - s = "def foo" + s + ": pass"
116c118
< @@ -1750,8 +1806,14 @@
---
> @@ -1750,8 +1805,14 @@
132,134c134,176
< diff -r 259857de72e1 Lib/test/test_capi.py
< --- a/Lib/test/test_capi.py Thu Feb 06 00:18:48 2014 -0500
< +++ b/Lib/test/test_capi.py Thu Feb 06 22:23:57 2014 -0800
---
> @@ -1768,7 +1829,7 @@
> kind = Parameter.VAR_KEYWORD
> p(f.args.kwarg, empty)
>
> - if first_parameter_is_self:
> + if self_parameter is not None:
> assert parameters
> if getattr(obj, '__self__', None):
> # strip off self, it's already been bound
> @@ -1861,12 +1922,13 @@
> # At this point we know, that `obj` is a class, with no user-
> # defined '__init__', '__new__', or class-level '__call__'
>
> - for base in obj.__mro__:
> + for base in obj.__mro__[:-1]:
> # Since '__text_signature__' is implemented as a
> # descriptor that extracts text signature from the
> # class docstring, if 'obj' is derived from a builtin
> # class, its own '__text_signature__' may be 'None'.
> - # Therefore, we go through the MRO to find the first
> + # Therefore, we go through the MRO (except the last
> + # class in there, which is 'object') to find the first
> # class with non-empty text signature.
> try:
> text_sig = base.__text_signature__
> @@ -1881,13 +1943,7 @@
> # No '__text_signature__' was found for the 'obj' class.
> # Last option is to check if its '__init__' is
> # object.__init__ or type.__init__.
> - if type in obj.__mro__:
> - # 'obj' is a metaclass without user-defined __init__
> - # or __new__.
> - if obj.__init__ is type.__init__:
> - # Return a signature of 'type' builtin.
> - return signature(type)
> - else:
> + if type not in obj.__mro__:
> # We have a class (not metaclass), but no user-defined
> # __init__ or __new__ for it
> if obj.__init__ is object.__init__:
> diff -r 844879389a17 Lib/test/test_inspect.py
> --- a/Lib/test/test_inspect.py Thu Feb 06 22:06:16 2014 -0500
> +++ b/Lib/test/test_inspect.py Fri Feb 07 13:41:22 2014 -0500
195c237
< @@ -2204,11 +2205,9 @@
---
> @@ -2204,11 +2205,11 @@
201d242
< + self.assertEqual(inspect.signature(C), None)
205c246,249
< + self.assertEqual(inspect.signature(D), None)
---
> + with self.assertRaisesRegex(ValueError, "callable.*is not supported"):
> + self.assertEqual(inspect.signature(C), None)
> + with self.assertRaisesRegex(ValueError, "callable.*is not supported"):
> + self.assertEqual(inspect.signature(D), None)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment