Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pydoc fails with the "unspecified" default value #64492

Closed
serhiy-storchaka opened this issue Jan 18, 2014 · 14 comments
Closed

pydoc fails with the "unspecified" default value #64492

serhiy-storchaka opened this issue Jan 18, 2014 · 14 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@serhiy-storchaka
Copy link
Member

BPO 20293
Nosy @larryhastings, @berkerpeksag, @serhiy-storchaka, @1st1

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2014-01-26.22:07:31.012>
created_at = <Date 2014-01-18.11:43:18.474>
labels = ['type-bug']
title = 'pydoc fails with the "unspecified" default value'
updated_at = <Date 2014-01-26.22:07:31.011>
user = 'https://github.com/serhiy-storchaka'

bugs.python.org fields:

activity = <Date 2014-01-26.22:07:31.011>
actor = 'serhiy.storchaka'
assignee = 'none'
closed = True
closed_date = <Date 2014-01-26.22:07:31.012>
closer = 'serhiy.storchaka'
components = []
creation = <Date 2014-01-18.11:43:18.474>
creator = 'serhiy.storchaka'
dependencies = []
files = []
hgrepos = []
issue_num = 20293
keywords = []
message_count = 14.0
messages = ['208394', '208405', '208407', '208411', '208457', '208466', '208477', '208799', '208801', '208802', '208805', '208806', '208807', '209358']
nosy_count = 4.0
nosy_names = ['larry', 'berker.peksag', 'serhiy.storchaka', 'yselivanov']
pr_nums = []
priority = 'normal'
resolution = 'out of date'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue20293'
versions = ['Python 3.4']

@serhiy-storchaka
Copy link
Member Author

With patch for the zlib module (bpo-20193) which uses the "unspecified" default value:

$ ./python -m pydoc zlib
Traceback (most recent call last):
  File "/home/serhiy/py/cpython/Lib/inspect.py", line 1997, in wrap_value
    value = eval(s, module_dict)
  File "<string>", line 1, in <module>
NameError: name 'unspecified' is not defined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/serhiy/py/cpython/Lib/inspect.py", line 2000, in wrap_value
    value = eval(s, sys_module_dict)
  File "<string>", line 1, in <module>
NameError: name 'unspecified' is not defined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/serhiy/py/cpython/Lib/runpy.py", line 189, in _run_module_as_main
    "__main__", mod_spec)
  File "/home/serhiy/py/cpython/Lib/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/serhiy/py/cpython/Lib/pydoc.py", line 2593, in <module>
    cli()
  File "/home/serhiy/py/cpython/Lib/pydoc.py", line 2558, in cli
    help.help(arg)
  File "/home/serhiy/py/cpython/Lib/pydoc.py", line 1840, in help
    elif request: doc(request, 'Help on %s:', output=self._output)
  File "/home/serhiy/py/cpython/Lib/pydoc.py", line 1578, in doc
    pager(render_doc(thing, title, forceload))
  File "/home/serhiy/py/cpython/Lib/pydoc.py", line 1571, in render_doc
    return title % desc + '\n\n' + renderer.document(object, name)
  File "/home/serhiy/py/cpython/Lib/pydoc.py", line 356, in document
    if inspect.ismodule(object): return self.docmodule(*args)
  File "/home/serhiy/py/cpython/Lib/pydoc.py", line 1142, in docmodule
    contents.append(self.document(value, key, name))
  File "/home/serhiy/py/cpython/Lib/pydoc.py", line 358, in document
    if inspect.isroutine(object): return self.docroutine(*args)
  File "/home/serhiy/py/cpython/Lib/pydoc.py", line 1323, in docroutine
    signature = inspect.signature(object)
  File "/home/serhiy/py/cpython/Lib/inspect.py", line 1468, in signature
    return Signature.from_builtin(obj)
  File "/home/serhiy/py/cpython/Lib/inspect.py", line 2052, in from_builtin
    p(name, default)
  File "/home/serhiy/py/cpython/Lib/inspect.py", line 2038, in p
    default_node = RewriteSymbolics().visit(default_node)
  File "/home/serhiy/py/cpython/Lib/ast.py", line 245, in visit
    return visitor(node)
  File "/home/serhiy/py/cpython/Lib/inspect.py", line 2030, in visit_Name
    return wrap_value(node.id)
  File "/home/serhiy/py/cpython/Lib/inspect.py", line 2002, in wrap_value
    raise RuntimeError()
RuntimeError

@serhiy-storchaka serhiy-storchaka added the type-bug An unexpected behavior, bug, or error label Jan 18, 2014
@larryhastings
Copy link
Contributor

Just checking--that happens with current trunk? Revision 32f9e0ae23f7 or newer?

@serhiy-storchaka
Copy link
Member Author

That happens with current trunk (revision 1469c4fde8cd) and a patch for zlib from bpo-20193 [1].

[1] http://bugs.python.org/file33523/zlib_clinic.patch

@larryhastings
Copy link
Contributor

I just built from a new clone of trunk, and it works fine for me. I didn't see the exception you report--I get the documentation for zlib.

Do you still get the error if you build from a new clone of the current trunk?

@berkerpeksag
Copy link
Member

I just built from a new clone of trunk, and it works fine for me.

It works fine for me, too (revision 8f11493cf727).

@larryhastings
Copy link
Contributor

Closing. Reopen it if you get a reproducible test case with a fresh checkout of trunk.

@serhiy-storchaka
Copy link
Member Author

I just built from a new clone of trunk (last revision is d0e2437136f5), and I still get the error.

@serhiy-storchaka
Copy link
Member Author

Seems this is related issue:

>>> import zlib, inspect
>>> zlib.compressobj.__text_signature__
'(level=Z_DEFAULT_COMPRESSION, method=DEFLATED, wbits=MAX_WBITS, memLevel=DEF_MEM_LEVEL, strategy=Z_DEFAULT_STRATEGY, zdict=None)'
>>> str(inspect.signature(zlib.compressobj))
'(level=-1, method=8, wbits=15, memLevel=8, strategy=0, zdict=None)'

help(zlib.compress) shows the '(bytes, level=-1)' signature.

inspect.signature() evaluates default values and instead of expected named constant it outputs numeric value which is often implementation detail.

@larryhastings
Copy link
Contributor

Yes, that is how it must work. This is symmetric with pure Python functions:

    >>> import inspect
    >>> import zlib
    >>> def foo(a=zlib.Z_DEFAULT_COMPRESSION): pass
    ... 
    >>> str(inspect.signature(foo))
    '(a=-1)'

@larryhastings
Copy link
Contributor

I missed the detail that you were working with a patch applied.

I suspect the problem is, you misspelled one of the expressions you provided as a default value. Try str(inspect.signature(x)) on every function you converted. I bet one of them will throw an exception.

Yes this is error-prone.

@serhiy-storchaka
Copy link
Member Author

Yes, that is how it must work. This is symmetric with pure Python
functions:

This is because in pure Python functions we have no enough information. I
believe than origin expression is more useful in the help. Compare:

>>> import re, inspect
>>> p = re.compile('')
>>> p.match.__text_signature__
'(string, pos=0, endpos=sys.maxsize)'
>>> str(inspect.signature(p.match))
'(string, pos=0, endpos=2147483647)'

I suspect the problem is, you misspelled one of the expressions you provided
as a default value.

>>> import zlib, inspect
>>> zlib.decompress.__text_signature__
'(data, wbits=unspecified, bufsize=unspecified)'
>>> str(inspect.signature(zlib.decompress))
Traceback (most recent call last):
  File "/home/serhiy/py/cpython/Lib/inspect.py", line 1997, in wrap_value
    value = eval(s, module_dict)
  File "<string>", line 1, in <module>
NameError: name 'unspecified' is not defined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/serhiy/py/cpython/Lib/inspect.py", line 2000, in wrap_value
    value = eval(s, sys_module_dict)
  File "<string>", line 1, in <module>
NameError: name 'unspecified' is not defined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/serhiy/py/cpython/Lib/inspect.py", line 1468, in signature
    return Signature.from_builtin(obj)
  File "/home/serhiy/py/cpython/Lib/inspect.py", line 2052, in from_builtin
    p(name, default)
  File "/home/serhiy/py/cpython/Lib/inspect.py", line 2038, in p
    default_node = RewriteSymbolics().visit(default_node)
  File "/home/serhiy/py/cpython/Lib/ast.py", line 245, in visit
    return visitor(node)
  File "/home/serhiy/py/cpython/Lib/inspect.py", line 2030, in visit_Name
    return wrap_value(node.id)
  File "/home/serhiy/py/cpython/Lib/inspect.py", line 2002, in wrap_value
    raise RuntimeError()
RuntimeError

@larryhastings
Copy link
Contributor

This is because in pure Python functions we have no enough
information. I believe than origin expression is more useful
in the help.

That doesn't matter. inspect.Signature would have to change in order to provide the original expression, and it's not going to for 3.4.

In zlib.decompress, remove the "= unspecified". You can have a c_default without a default value now.

@serhiy-storchaka
Copy link
Member Author

Without the "= unspecified" parameters will be non-optional.

@serhiy-storchaka
Copy link
Member Author

Since Argument Clinic no more supports "unspecified" default value, this issue can be closed.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants