Repository navigation
Commit f767423
These exceptions and their subclasses had no vectorcall, and `__init__`
parsed keywords through PyArg_ParseTupleAndKeywords with a temporary
empty tuple on every call. Error messages are unchanged except when more
keywords than parameters are given, which now names the unexpected
keyword.
The clinic inputs have no docstring, so docstrings are unchanged and
these exceptions don't gain a `__text_signature__`.
pyperf microbenchmark (PGO+LTO, run serially):
| Benchmark | base | vectorcall |
|----------------------------------|:-------:|:---------------------:|
| AttributeError(s, name=s, obj=s) | 127 ns | 41.9 ns: 3.02x faster |
| ImportError(s, name=s, path=s) | 129 ns | 43.4 ns: 2.96x faster |
| NameError(s, name=s) | 88.3 ns | 39.3 ns: 2.24x faster |
| ModuleNotFoundError(s, name=s) | 89.9 ns | 40.6 ns: 2.21x faster |
| AttributeError(s) | 39.4 ns | 32.1 ns: 1.23x faster |
| UnboundLocalError(s) | 38.6 ns | 31.8 ns: 1.22x faster |
| NameError(s) | 38.5 ns | 32.2 ns: 1.19x faster |
| ImportError(s) | 40.7 ns | 34.4 ns: 1.18x faster |
| attribute_error_to_none() | 176 ns | 173 ns: 1.02x faster |
Benchmark code:
```python
import pyperf
runner = pyperf.Runner()
setup = """s = 'x'
class O: pass
o = O()
def attribute_error_to_none():
try:
o.x
except AttributeError:
pass
"""
for stmt in ["AttributeError(s)", "AttributeError(s, name=s, obj=s)",
"NameError(s)", "NameError(s, name=s)",
"ImportError(s)", "ImportError(s, name=s, path=s)",
"ModuleNotFoundError(s, name=s)", "UnboundLocalError(s)",
"attribute_error_to_none()"]:
runner.timeit(stmt, stmt, setup)
```
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 5f46ac9 commit f767423
4 files changed
Lines changed: 389 additions & 55 deletions
File tree
- Lib/test
- Misc/NEWS.d/next/Core_and_Builtins
- Objects
- clinic
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
208 | 208 | | |
209 | 209 | | |
210 | 210 | | |
211 | | - | |
| 211 | + | |
212 | 212 | | |
213 | 213 | | |
214 | 214 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments