Commit 79311cb
authored
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`.
1 parent c615286 commit 79311cb
File tree
3 files changed
+46
-6
lines changed- Lib
- test
- Misc/NEWS.d/next/Library
3 files changed
+46
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2122 | 2122 | | |
2123 | 2123 | | |
2124 | 2124 | | |
2125 | | - | |
| 2125 | + | |
2126 | 2126 | | |
2127 | 2127 | | |
2128 | 2128 | | |
| |||
2221 | 2221 | | |
2222 | 2222 | | |
2223 | 2223 | | |
2224 | | - | |
| 2224 | + | |
2225 | 2225 | | |
2226 | 2226 | | |
2227 | 2227 | | |
2228 | | - | |
| 2228 | + | |
2229 | 2229 | | |
2230 | 2230 | | |
2231 | 2231 | | |
| |||
2235 | 2235 | | |
2236 | 2236 | | |
2237 | 2237 | | |
2238 | | - | |
| 2238 | + | |
2239 | 2239 | | |
2240 | 2240 | | |
2241 | 2241 | | |
| |||
2245 | 2245 | | |
2246 | 2246 | | |
2247 | 2247 | | |
| 2248 | + | |
| 2249 | + | |
| 2250 | + | |
| 2251 | + | |
| 2252 | + | |
| 2253 | + | |
| 2254 | + | |
| 2255 | + | |
| 2256 | + | |
| 2257 | + | |
| 2258 | + | |
| 2259 | + | |
| 2260 | + | |
| 2261 | + | |
| 2262 | + | |
2248 | 2263 | | |
2249 | 2264 | | |
2250 | 2265 | | |
2251 | 2266 | | |
2252 | 2267 | | |
2253 | 2268 | | |
2254 | 2269 | | |
2255 | | - | |
| 2270 | + | |
2256 | 2271 | | |
2257 | 2272 | | |
2258 | 2273 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2525 | 2525 | | |
2526 | 2526 | | |
2527 | 2527 | | |
2528 | | - | |
| 2528 | + | |
2529 | 2529 | | |
2530 | 2530 | | |
2531 | 2531 | | |
| |||
4323 | 4323 | | |
4324 | 4324 | | |
4325 | 4325 | | |
| 4326 | + | |
4326 | 4327 | | |
4327 | 4328 | | |
4328 | 4329 | | |
4329 | 4330 | | |
| 4331 | + | |
| 4332 | + | |
| 4333 | + | |
| 4334 | + | |
| 4335 | + | |
| 4336 | + | |
| 4337 | + | |
| 4338 | + | |
| 4339 | + | |
| 4340 | + | |
| 4341 | + | |
| 4342 | + | |
| 4343 | + | |
| 4344 | + | |
| 4345 | + | |
| 4346 | + | |
| 4347 | + | |
| 4348 | + | |
4330 | 4349 | | |
4331 | 4350 | | |
4332 | 4351 | | |
| |||
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
0 commit comments