Repository navigation
Help text of builtin functions – missing signatures #107526
Copy link
Copy link
Closed
Labels
3.12only security fixesonly security fixes3.13only security fixesonly security fixesrelease-blockertype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
I don't understand the deep details here but I think something went wrong in commit bdfb694 when some of the builtin functions where transferred to argument clinic.
The problem I see is in the help texts of those functions. Here are a few examples of help(<function>):
iter
Python 3.11.4
Help on built-in function iter in module builtins:
iter(...)
iter(iterable) -> iterator
iter(callable, sentinel) -> iterator
Get an iterator from an object. In the first form, the argument must
supply its own iterator, or be a sequence.
In the second form, the callable is called until it returns the sentinel.
Python 3.12.0b4
Help on built-in function iter in module builtins:
iter(...)
Get an iterator from an object.
In the first form, the argument must supply its own iterator, or be a sequence.
In the second form, the callable is called until it returns the sentinel.
As you can see, the help in 3.12 is talking about two forms but there are no signatures so it doesn't make sense.
next
Python 3.11.4
Help on built-in function next in module builtins:
next(...)
next(iterator[, default])
Return the next item from the iterator. If default is given and the iterator
is exhausted, it is returned instead of raising StopIteration.
Python 3.12.0b4
Help on built-in function next in module builtins:
next(...)
Return the next item from the iterator.
If default is given and the iterator is exhausted,
it is returned instead of raising StopIteration.
Again, the help text talks about iterator and default but missing signature means that the reader might not know what those are.
getattr
Python 3.11.4
Help on built-in function getattr in module builtins:
getattr(...)
getattr(object, name[, default]) -> value
Get a named attribute from an object; getattr(x, 'y') is equivalent to x.y.
When a default argument is given, it is returned when the attribute doesn't
exist; without it, an exception is raised in that case.
Python 3.12.0b4
Help on built-in function getattr in module builtins:
getattr(...)
Get a named attribute from an object.
getattr(x, 'y') is equivalent to x.y
When a default argument is given, it is returned when the attribute doesn't
exist; without it, an exception is raised in that case.
Again, a similar case here.
Linked PRs
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
3.12only security fixesonly security fixes3.13only security fixesonly security fixesrelease-blockertype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Projects
- StatusShow more project fieldsDone
Activity
sobolevn commentedon Aug 1, 2023
Yes, this is because of
NULLdefault :(arg: object = NULLfrenzymadness commentedon Aug 1, 2023
Is there any way to fix it?
sobolevn commentedon Aug 1, 2023
I've submitted https://discuss.python.org/t/ac-null-defaults-prevent-correct-signatures-lets-add-inspect-unrepresentable-to-fix-this/30753
I wanted to do it for quite a long time, sorry for ignoring this item in my backlog :)
encukou commentedon Aug 1, 2023
Is this feasible for 3.11?
If not, should we add the signatures to the doc text manually, in these cases where AC doesn't generate anything?
FWIW, this breaks Jedi, which currently parses the manually-formatted signatures in docstrings: davidhalter/jedi#1952
They would be happy to move to
inspect.signatureonce that works. Until it does, parsing__doc__seems like a sensible workaround, so this might be considered a regression.So I'm flagging this as a potential blocker.
1 remaining item
encukou commentedon Aug 1, 2023
I meant 3.12, not 3.11. Got my version numbers mixed up, sorry!
JelleZijlstra commentedon Aug 1, 2023
The fix @sobolevn proposes doesn't seem feasible for 3.12, as it requires introducing a new object in the
inspectmodule. As a less invasive fix, maybe we can directly add these signatures to the docstrings?sobolevn commentedon Aug 1, 2023
@JelleZijlstra that's exactly what I am proposing for 3.11 and 3.12 in #107526 (comment) :)
sobolevn commentedon Aug 1, 2023
Ok, I think that we would need to revert these changes. Here's why:
outputs:
But, that's not what we want!
only_docstringoption for functions, but I will need to rework how it sets this value toTrueto be able to use it. This would require extra testing and stuffpythongh-107526: Revert "pythongh-100357: Convert several functions i…
davidhalter commentedon Aug 2, 2023
FYI I don't think the effects on Jedi are extreme (speaking as its author). It's just that it's a bit unfortunate that the signatures won't be shown anymore in that case for 3.12. So yes, it's a regression, but not a problematic regression. So if argument clinic helps you here with other issues, it might just be worth keeping it. IMO the more problematic change here might be that the docstrings are just not as good as they were previously. Especially for
iterthe docstring talks aboutIn the first form, [...]. What is the first form? In the other docstrings there are weird comments as well.In the end it would be really nice if these functions were eventually supported by
inspect.signature, but I don't think you need to hurry there either.serhiy-storchaka commentedon Aug 9, 2023
#107782 can help.
gh-107526: Revert "gh-100357: Convert several functions in bltinsmodu…
gh-107526: Fix test_module_level_callable_unrepresentable_default (gh…
JelleZijlstra commentedon Nov 9, 2023
The immediate issue was fixed here. We still have the broader issue that
inspect.signaturecan't handle `', but that's tracked in #87233.[3.12] pythongh-107526: Revert "pythongh-100357: Convert several func…
[3.12] gh-107526: Revert "gh-100357: Convert several functions in blt…