ImageImage

This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: inspect.signature() doesn't parse __text_signature__ containing a newline character
Type: Stage: patch review
Components: Library (Lib) Versions: Python 3.10
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Anthony Sottile, serhiy.storchaka, vstinner, yselivanov
Priority: normal Keywords: patch

Created on 2020-06-23 22:26 by vstinner, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 21066 Anthony Sottile, 2020-06-23 22:27
Messages (2)
msg372213 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-06-23 22:26
$ ./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.
(...)
---
msg372222 - (view) Author: Anthony Sottile (Anthony Sottile) * Date: 2020-06-24 01:12
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

1. https://github.com/python/cpython/pull/21100
2. 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
History
Date User Action Args
2022-04-11 14:59:32adminsetgithub: 85267
2020-06-24 01:12:14Anthony Sottilesetmessages: + msg372222
2020-06-23 22:27:45Anthony Sottilesetkeywords: + patch
nosy: + Anthony Sottile

pull_requests: + pull_request20269
stage: patch review
2020-06-23 22:26:29vstinnercreate