On 3/7/2014 3:10 PM, Jurko Gospodnetić wrote: > Hi. > > I just noticed that the way help() function displays a function > signature changed between Python 3.3 & 3.4 but I can not find this > documented anywhere. Here's a matching example in both Python 3.3 & > Python 3.4 for comparison: > > ---------------------------------------- > >> Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:19:30) [MSC v.1600 >> 64 bit (AMD64)] on win32 >> Type "help", "copyright", "credits" or "license" for more information. >>>>> def f(a, b, c): >> ... print(a, b, c) >> ... >>>>> def g(*args, **kwargs): >> ... f(*args, **kwargs) >> ... >>>>> import inspect >>>>> print(inspect.signature(f)) >> (a, b, c) >>>>> print(inspect.signature(g)) >> (*args, **kwargs) >>>>> g.__wrapped__ = f >>>>> print(inspect.signature(f)) >> (a, b, c) >>>>> print(inspect.signature(g)) >> (a, b, c) >>>>> help(f) >> Help on function f in module __main__: >> >> f(a, b, c) >> >>>>> help(g) >> Help on function g in module __main__: >> >> g(*args, **kwargs) > > ---------------------------------------- > >> Python 3.4.0b3 (v3.4.0b3:a97ce3ecc96a, Jan 26 2014, 17:50:55) [MSC >> v.1600 64 bit (AMD64)] on win32 >> Type "help", "copyright", "credits" or "license" for more information. >>>>> def f(a, b, c): >> ... print(a, b, c) >> ... >>>>> def g(*args, **kwargs): >> ... f(*args, **kwargs) >> ... >>>>> import inspect >>>>> print(inspect.signature(f)) >> (a, b, c) >>>>> print(inspect.signature(g)) >> (*args, **kwargs) >>>>> g.__wrapped__ = f >>>>> print(inspect.signature(f)) >> (a, b, c) >>>>> print(inspect.signature(g)) >> (a, b, c) >>>>> help(f) >> Help on function f in module __main__: >> >> f(a, b, c) >> >>>>> help(g) >> Help on function g in module __main__: >> >> g(a, b, c) > > ---------------------------------------- > > As you can see by comparing those two outputs, setting the __wrapped__ > attribute on a wrapper function affects the inspect.signature() results > on that function. This behaviour is the same in both Python 3.3. & 3.4 > and is (somewhat) described in the Python documentation. I suspect that is it intentional that the output of help is not exactly defined, just as exception messages are not. We consider either fair game to be changed in new versions. > However, help() output is not affected by this in Python 3.3, That was a bug. > but is > affected in Python 3.4, and I can not find anything regarding this in > the Python 3.4 docs. Assuming that pydoc (and hence help()) have not (yet?) been switched to using .signature directly, I suspect this is a side-effect of http://bugs.python.org/issue17481 inspect.getfullargspec should use __signature__ > Can something related to this be added at least to the 'what's changed' > docs, if not to the help() documentation as well? Perhaps add something to Other Language Changes ---------------------- * Signatures reported by help() have been modified and improved by Argument Clinic and changes to the inspect module. -- Terry Jan Reedy
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4