inspect.signature() doesn't parse __text_signature__ containing a newline character
| BPO | 41095 |
|---|---|
| Nosy | @vstinner, @serhiy-storchaka, @1st1, @asottile |
| PRs |
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 = None
created_at = <Date 2020-06-23.22:26:29.252>
labels = ['library', '3.10']
title = "inspect.signature() doesn't parse __text_signature__ containing a newline character"
updated_at = <Date 2020-06-24.01:12:14.804>
user = 'https://github.com/vstinner'
bugs.python.org fields:
activity = <Date 2020-06-24.01:12:14.804>
actor = 'Anthony Sottile'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2020-06-23.22:26:29.252>
creator = 'vstinner'
dependencies = []
files = []
hgrepos = []
issue_num = 41095
keywords = ['patch']
message_count = 2.0
messages = ['372213', '372222']
nosy_count = 4.0
nosy_names = ['vstinner', 'serhiy.storchaka', 'yselivanov', 'Anthony Sottile']
pr_nums = ['21066']
priority = 'normal'
resolution = None
stage = 'patch review'
status = 'open'
superseder = None
type = None
url = 'https://bugs.python.org/issue41095'
versions = ['Python 3.10']
- PR: gh-98796
$ ./python
Python 3.10.0a0 (heads/unicode_latin1:40855c7064, Jun 24 2020, 00:20:07)
>>> import select
>>> select.epoll.register.__text_signature__
'($self, /, fd,\n eventmask=select.EPOLLIN | select.EPOLLPRI | select.EPOLLOUT)'
>>> import inspect
>>> inspect.signature(select.epoll.register)
<Signature (self, /, fd)>
=> eventmask parameter is gone!
Either signature() must raise an exception, or it must handle a __text_signature__ containing a newline character.
Issue spotted on bpo-31938 when fixing "./python -m pydoc select".
By the way, as expected, pydoc shows:
Help on method_descriptor in select.epoll: ---
$ ./python -m pydoc select.epoll.register
select.epoll.register = register(self, /, fd)
Registers a new fd or raises an OSError if the fd is already registered.
(...)
Looking into this, it appears to be due to the default value and not due to the newline
I've stumbled upon two simplifications to the routines in inspect but not a fix for this
- https://github.com/python/cpython/pull/21100
- https://github.com/python/cpython/pull/21104
the following code is hit because ast.literal_eval(...) fails for the |d expression:
https://github.com/python/cpython/blob/2f9ada96e0d420fed0d09a032b37197f08ef167a/Lib/inspect.py#L2069-L2070
this causes the parameter to be skipped entirely
Sadly, I don't have the bandwidth to work on this issue, so I just close it.
Reopening as there's an active PR fixing this.
What is the active PR?
#98796