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
help(open) eats first line #64274
Comments
The output of help(open) (and Help on built-in function open in module io: open(...)
errors=None, newline=None, closefd=True, opener=None) -> file object
Open file and return a stream. Raise IOError upon failure.
... In 3.3 and older it works correctly: Help on built-in function open in module io: open(...)
open(file, mode='r', buffering=-1, encoding=None,
errors=None, newline=None, closefd=True, opener=None) -> file object
Open file and return a stream. Raise IOError upon failure.
... |
Interestingly, it doesn't look like pydoc's fault: P:\ath\to\cpython\>PCbuild\python_d.exe -ISc "import sys;print(sys.version);print(open.__doc__[:75]);print('pydoc' in sys.modules)" False |
Indeed. However in Modules/_io/_iomodule.c: PyDoc_STRVAR(open_doc, Perhaps Larry has relations to this. |
Looks like the changes from 78ec18f5cb45 attempt to skip the signature, |
Hi guys, probably this patch can fix it? |
LGTM. |
The patch does not fix it. It becomes like this: open(...)
Open file and return a stream. Raise IOError upon failure. It's not just help(open) has problem, help(sqlite3.connect) got it as well: connect(...)
check_same_thread, factory, cached_statements, uri])
Opens a connection to the SQLite database file *database*. You can use |
The best fix would be to convert the docstrings to something inspect can parse. Preferably by converting the functions to use Argument Clinic, though you could manually mark up the docstring by hand if necessary. |
We can't check all docstrings in the stdlib and in all third-party libraries. |
Yes, so basically signature line in help(open) is not shown because ast.parse fails to parse the return value -> file object According to grammar, it should be as for sqlite, it fails to parse square brackets: connect(database[, timeout, detect_types, isolation_level,\n\
check_same_thread, factory, cached_statements, uri]) As an idea, maybe we can come up with a failover i.e. if ast can't parse the signature, just use __text_signature__ instead of signature object: Lib/pydoc.py:1325
Or probably just don't show the signature if it is not formatted correctly as it is now (after the patch applied). |
The patch looks good to me (aside from extra whitespace on the blank lines in methodobject.c, and I agree with Serhiy about s/brackets/parens/). Also, I like the suggestion of using text_signature instead of '(...)'. However, just to avoid any possible issues with text_signature being blank or missing, I would go with |
Thank you for the comments! I'll update the patch. BTW is it safe to update Lib/inspect.py:2004 ?
Looks like the return value is not shown in signature (if it parsed correctly) because currently we explicitly pass cls.empty instance, but if we'd pass f.returns.s, the return value is shown. Or it is correct behavior? |
So, looks like it works for me and all tests pass. |
One of the relevant PEPs (PEP-8? PEP-7? the annotations PEP?) states that the Python standard library is not permitted to use annotations. And considering that Argument Clinic is an internal-only tool, we could probably justify the decision to not allow annotations to creep through. That said, I think it's harmless, and it might be useful to somebody, so go ahead and propagate the annotation from the __text_signature__ into inspect.Signature if we get a valid one. But please create a separate issue for it. (I encourage you to cut-and-paste this text into the description of that new issue.) |
I'm sorry, I'm not sure I caught the idea. So, I need to create an issue with description "propagate the annotation from the __text_signature__ into inspect.Signature if we get a valid one." ? |
Zachary, thank you for review. Here's the updated patch. |
Gennadiy, sorry this stalled out like it did. The patched function will be moving as part of bpo-20189. Larry, if you want to incorporate this patch into that patch, please do so; otherwise I'll get this one updated and committed as soon after you commit that one as I can. Gennadiy, if you beat me to updating this patch after Larry commits bpo-20189, please do so. (Setting priority as 'critical' since it would be quite embarrassing to release 3.4.0 with broken "help(open)".) |
See also bpo-20326. |
With bpo-20326 fixed, this is no longer an issue. Gennadiy, thank you for the patch, and I'm sorry it ended up being unused. |
Yup, sorry about that. We're moving pretty fast with the Derby right now, and sometimes we don't figure out something important until later, and sometimes that means wasted effort. Sorry! |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: