[Python-Dev] undocumented help() function change in Python 3.4? (original) (raw)

Terry Reedy tjreedy at udel.edu
Sat Mar 8 02:29:26 CET 2014


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

-- Terry Jan Reedy



More information about the Python-Dev mailing list