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

inspect.signature throws RuntimeError on select.epoll.register #83685

Open
hauntsaninja opened this issue Jan 31, 2020 · 1 comment
Open

inspect.signature throws RuntimeError on select.epoll.register #83685

hauntsaninja opened this issue Jan 31, 2020 · 1 comment
Labels
stdlib Python modules in the Lib dir

Comments

@hauntsaninja
Copy link
Contributor

hauntsaninja commented Jan 31, 2020

BPO 39504
Nosy @hauntsaninja

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-01-31.02:12:38.905>
labels = ['library']
title = 'inspect.signature throws RuntimeError on select.epoll.register'
updated_at = <Date 2020-01-31.02:12:38.905>
user = 'https://github.com/hauntsaninja'

bugs.python.org fields:

activity = <Date 2020-01-31.02:12:38.905>
actor = 'hauntsaninja'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2020-01-31.02:12:38.905>
creator = 'hauntsaninja'
dependencies = []
files = []
hgrepos = []
issue_num = 39504
keywords = []
message_count = 1.0
messages = ['361089']
nosy_count = 1.0
nosy_names = ['hauntsaninja']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = None
url = 'https://bugs.python.org/issue39504'
versions = []

@hauntsaninja
Copy link
Contributor Author

hauntsaninja commented Jan 31, 2020

From the documentation of inspect.signature it seems we should never have a RuntimeError:

Raises ValueError if no signature can be provided, and TypeError if that type of object is not supported.

The easiest thing to do is just turn the RuntimeError into a ValueError... but I'll take a deeper look and see if I can actually fix this.

Traceback below:

>>> import sys
>>> sys.version
'3.8.0 (default, Nov 14 2019, 22:29:45) \n[GCC 5.4.0 20160609]'
>>> import inspect
>>> import select
>>> inspect.signature(select.epoll.register)
Traceback (most recent call last):
  File "/usr/lib/python3.8/inspect.py", line 2004, in wrap_value
    value = eval(s, module_dict)
  File "<string>", line 1, in <module>
NameError: name 'EPOLLIN' is not defined
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/lib/python3.8/inspect.py", line 2007, in wrap_value
    value = eval(s, sys_module_dict)
  File "<string>", line 1, in <module>
NameError: name 'EPOLLIN' is not defined
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.8/inspect.py", line 3093, in signature
    return Signature.from_callable(obj, follow_wrapped=follow_wrapped)
  File "/usr/lib/python3.8/inspect.py", line 2842, in from_callable
    return _signature_from_callable(obj, sigcls=cls,
  File "/usr/lib/python3.8/inspect.py", line 2296, in _signature_from_callable
    return _signature_from_builtin(sigcls, obj,
  File "/usr/lib/python3.8/inspect.py", line 2109, in _signature_from_builtin
    return _signature_fromstr(cls, func, s, skip_bound_arg)
  File "/usr/lib/python3.8/inspect.py", line 2057, in _signature_fromstr
    p(name, default)
  File "/usr/lib/python3.8/inspect.py", line 2039, in p
    default_node = RewriteSymbolics().visit(default_node)
  File "/usr/lib/python3.8/ast.py", line 360, in visit
    return visitor(node)
  File "/usr/lib/python3.8/ast.py", line 445, in generic_visit
    new_node = self.visit(old_value)
  File "/usr/lib/python3.8/ast.py", line 360, in visit
    return visitor(node)
  File "/usr/lib/python3.8/ast.py", line 445, in generic_visit
    new_node = self.visit(old_value)
  File "/usr/lib/python3.8/ast.py", line 360, in visit
    return visitor(node)
  File "/usr/lib/python3.8/inspect.py", line 2031, in visit_Name
    return wrap_value(node.id)
  File "/usr/lib/python3.8/inspect.py", line 2009, in wrap_value
    raise RuntimeError()
RuntimeError

@hauntsaninja hauntsaninja added stdlib Python modules in the Lib dir labels Jan 31, 2020
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
hauntsaninja added a commit to hauntsaninja/cpython that referenced this issue Oct 28, 2022
…handling

This makes a couple related changes to inspect.signature's behaviour
when parsing a signature from `__text_signature__`.

First, `inspect.signature` is documented as only raising ValueError or
TypeError. However, in some cases, we could raise RuntimeError.  This PR
changes that, thereby fixing python#83685.

(Note that the new ValueErrors in RewriteSymbolics are caught and then
reraised with a message)

Second, `inspect.signature` could randomly drop parameters that it
didn't understand (corresponding to `return None` in the `p` function).
This is the core issue in python#85267. I think this is very surprising
behaviour and it seems better to fail outright.

Third, adding this new failure broke a couple tests. To fix them (and to
e.g. allow `inspect.signature(select.epoll.register)` as in python#85267), I
add constant folding of a couple binary operations to RewriteSymbolics.

(There's some discussion of making signature expression evaluation
arbitrary powerful in python#68155. I think that's out of scope. The
additional constant folding here is pretty straightforward, useful, and
not much of a slippery slope)

Fourth, while python#85267 is incorrect about the cause of the issue, it turns
out if you had consecutive newlines in __text_signature__, you'd get
`tokenize.TokenError`.

Finally, the `if name is invalid:` code path was dead, since
`parse_name` never returned `invalid`.
JelleZijlstra pushed a commit that referenced this issue Dec 21, 2022
…ng (#98796)

This makes a couple related changes to inspect.signature's behaviour
when parsing a signature from `__text_signature__`.

First, `inspect.signature` is documented as only raising ValueError or
TypeError. However, in some cases, we could raise RuntimeError.  This PR
changes that, thereby fixing #83685.

(Note that the new ValueErrors in RewriteSymbolics are caught and then
reraised with a message)

Second, `inspect.signature` could randomly drop parameters that it
didn't understand (corresponding to `return None` in the `p` function).
This is the core issue in #85267. I think this is very surprising
behaviour and it seems better to fail outright.

Third, adding this new failure broke a couple tests. To fix them (and to
e.g. allow `inspect.signature(select.epoll.register)` as in #85267), I
add constant folding of a couple binary operations to RewriteSymbolics.

(There's some discussion of making signature expression evaluation
arbitrary powerful in #68155. I think that's out of scope. The
additional constant folding here is pretty straightforward, useful, and
not much of a slippery slope)

Fourth, while #85267 is incorrect about the cause of the issue, it turns
out if you had consecutive newlines in __text_signature__, you'd get
`tokenize.TokenError`.

Finally, the `if name is invalid:` code path was dead, since
`parse_name` never returned `invalid`.
hauntsaninja added a commit to hauntsaninja/cpython that referenced this issue Dec 21, 2022
…ture__ handling (pythonGH-98796)

This makes a couple related changes to inspect.signature's behaviour
when parsing a signature from `__text_signature__`.

First, `inspect.signature` is documented as only raising ValueError or
TypeError. However, in some cases, we could raise RuntimeError.  This PR
changes that, thereby fixing pythonGH-83685.

(Note that the new ValueErrors in RewriteSymbolics are caught and then
reraised with a message)

Second, `inspect.signature` could randomly drop parameters that it
didn't understand (corresponding to `return None` in the `p` function).
This is the core issue in pythonGH-85267. I think this is very surprising
behaviour and it seems better to fail outright.

Third, adding this new failure broke a couple tests. To fix them (and to
e.g. allow `inspect.signature(select.epoll.register)` as in pythonGH-85267), I
add constant folding of a couple binary operations to RewriteSymbolics.

(There's some discussion of making signature expression evaluation
arbitrary powerful in pythonGH-68155. I think that's out of scope. The
additional constant folding here is pretty straightforward, useful, and
not much of a slippery slope)

Fourth, while pythonGH-85267 is incorrect about the cause of the issue, it turns
out if you had consecutive newlines in __text_signature__, you'd get
`tokenize.TokenError`.

Finally, the `if name is invalid:` code path was dead, since
`parse_name` never returned `invalid`..
(cherry picked from commit 79311cb)

Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
hauntsaninja added a commit to hauntsaninja/cpython that referenced this issue Dec 21, 2022
…ture__ handling (pythonGH-98796)

This makes a couple related changes to inspect.signature's behaviour
when parsing a signature from `__text_signature__`.

First, `inspect.signature` is documented as only raising ValueError or
TypeError. However, in some cases, we could raise RuntimeError.  This PR
changes that, thereby fixing pythonGH-83685.

(Note that the new ValueErrors in RewriteSymbolics are caught and then
reraised with a message)

Second, `inspect.signature` could randomly drop parameters that it
didn't understand (corresponding to `return None` in the `p` function).
This is the core issue in pythonGH-85267. I think this is very surprising
behaviour and it seems better to fail outright.

Third, adding this new failure broke a couple tests. To fix them (and to
e.g. allow `inspect.signature(select.epoll.register)` as in pythonGH-85267), I
add constant folding of a couple binary operations to RewriteSymbolics.

(There's some discussion of making signature expression evaluation
arbitrary powerful in pythonGH-68155. I think that's out of scope. The
additional constant folding here is pretty straightforward, useful, and
not much of a slippery slope)

Fourth, while pythonGH-85267 is incorrect about the cause of the issue, it turns
out if you had consecutive newlines in __text_signature__, you'd get
`tokenize.TokenError`.

Finally, the `if name is invalid:` code path was dead, since
`parse_name` never returned `invalid`..
(cherry picked from commit 79311cb)

Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
JelleZijlstra pushed a commit that referenced this issue Dec 21, 2022
… handling (GH-98796) (#100392)

This makes a couple related changes to inspect.signature's behaviour
when parsing a signature from `__text_signature__`.

First, `inspect.signature` is documented as only raising ValueError or
TypeError. However, in some cases, we could raise RuntimeError.  This PR
changes that, thereby fixing GH-83685.

(Note that the new ValueErrors in RewriteSymbolics are caught and then
reraised with a message)

Second, `inspect.signature` could randomly drop parameters that it
didn't understand (corresponding to `return None` in the `p` function).
This is the core issue in GH-85267. I think this is very surprising
behaviour and it seems better to fail outright.

Third, adding this new failure broke a couple tests. To fix them (and to
e.g. allow `inspect.signature(select.epoll.register)` as in GH-85267), I
add constant folding of a couple binary operations to RewriteSymbolics.

(There's some discussion of making signature expression evaluation
arbitrary powerful in GH-68155. I think that's out of scope. The
additional constant folding here is pretty straightforward, useful, and
not much of a slippery slope)

Fourth, while GH-85267 is incorrect about the cause of the issue, it turns
out if you had consecutive newlines in __text_signature__, you'd get
`tokenize.TokenError`.

Finally, the `if name is invalid:` code path was dead, since
`parse_name` never returned `invalid`..
(cherry picked from commit 79311cb)

Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
JelleZijlstra pushed a commit that referenced this issue Dec 21, 2022
… handling (GH-98796) (#100393)

This makes a couple related changes to inspect.signature's behaviour
when parsing a signature from `__text_signature__`.

First, `inspect.signature` is documented as only raising ValueError or
TypeError. However, in some cases, we could raise RuntimeError.  This PR
changes that, thereby fixing GH-83685.

(Note that the new ValueErrors in RewriteSymbolics are caught and then
reraised with a message)

Second, `inspect.signature` could randomly drop parameters that it
didn't understand (corresponding to `return None` in the `p` function).
This is the core issue in GH-85267. I think this is very surprising
behaviour and it seems better to fail outright.

Third, adding this new failure broke a couple tests. To fix them (and to
e.g. allow `inspect.signature(select.epoll.register)` as in GH-85267), I
add constant folding of a couple binary operations to RewriteSymbolics.

(There's some discussion of making signature expression evaluation
arbitrary powerful in GH-68155. I think that's out of scope. The
additional constant folding here is pretty straightforward, useful, and
not much of a slippery slope)

Fourth, while GH-85267 is incorrect about the cause of the issue, it turns
out if you had consecutive newlines in __text_signature__, you'd get
`tokenize.TokenError`.

Finally, the `if name is invalid:` code path was dead, since
`parse_name` never returned `invalid`..
(cherry picked from commit 79311cb)

Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir
Projects
None yet
Development

No branches or pull requests

1 participant