Repository navigation
Commit 806f101
Generate complex.__new__ and its vectorcall with Argument Clinic. To keep
accepting a string only as a positional argument (complex('1') but not
complex(real='1')), real and imag are declared twice: positional-only and
keyword-only, with @text_signature keeping the visible "(real=0, imag=0)".
The previous hand-written tp_new wrapper becomes the one-argument
conversion called from complex_new_impl().
Error messages change when more than two arguments are passed in total:
a duplicated or unknown keyword is now reported as such instead of
"takes at most 2 arguments (N given)".
Microbenchmarks (pyperf, PGO+LTO):
| Benchmark | main | patch |
|-------------------------------------|:-------:|:---------------------:|
| complex(real=a_float, imag=a_float) | 67.4 ns | 37.9 ns: 1.78x faster |
| complex(a_float, imag=a_float) | 62.2 ns | 39.2 ns: 1.59x faster |
| complex(a_complex) | 18.9 ns | 12.0 ns: 1.57x faster |
| complex(a_float, a_float) | 38.0 ns | 29.2 ns: 1.30x faster |
| complex(an_int) | 36.9 ns | 29.9 ns: 1.24x faster |
| complex(a_float) | 31.0 ns | 26.0 ns: 1.19x faster |
| complex(a_str) | 48.4 ns | 41.8 ns: 1.16x faster |
| complex() | 21.1 ns | 18.5 ns: 1.14x faster |
Subclass construction (no vectorcall) is unchanged.
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent af047f2 commit 806f101
3 files changed
Lines changed: 102 additions & 34 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
609 | 609 | | |
610 | 610 | | |
611 | 611 | | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
612 | 618 | | |
613 | 619 | | |
614 | 620 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1124 | 1124 | | |
1125 | 1125 | | |
1126 | 1126 | | |
1127 | | - | |
1128 | | - | |
1129 | | - | |
1130 | | - | |
1131 | | - | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
1132 | 1132 | | |
1133 | 1133 | | |
1134 | 1134 | | |
1135 | | - | |
| 1135 | + | |
1136 | 1136 | | |
1137 | 1137 | | |
1138 | 1138 | | |
1139 | 1139 | | |
1140 | | - | |
1141 | | - | |
1142 | | - | |
1143 | | - | |
1144 | | - | |
1145 | | - | |
1146 | | - | |
1147 | | - | |
1148 | 1140 | | |
1149 | 1141 | | |
1150 | 1142 | | |
| |||
1193 | 1185 | | |
1194 | 1186 | | |
1195 | 1187 | | |
| 1188 | + | |
1196 | 1189 | | |
| 1190 | + | |
1197 | 1191 | | |
1198 | | - | |
1199 | | - | |
| 1192 | + | |
| 1193 | + | |
| 1194 | + | |
| 1195 | + | |
| 1196 | + | |
| 1197 | + | |
1200 | 1198 | | |
1201 | 1199 | | |
1202 | 1200 | | |
| |||
1207 | 1205 | | |
1208 | 1206 | | |
1209 | 1207 | | |
1210 | | - | |
1211 | | - | |
| 1208 | + | |
| 1209 | + | |
| 1210 | + | |
1212 | 1211 | | |
1213 | 1212 | | |
1214 | 1213 | | |
| |||
1217 | 1216 | | |
1218 | 1217 | | |
1219 | 1218 | | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
1220 | 1240 | | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + | |
1221 | 1244 | | |
1222 | 1245 | | |
1223 | 1246 | | |
| |||
1457 | 1480 | | |
1458 | 1481 | | |
1459 | 1482 | | |
1460 | | - | |
| 1483 | + | |
1461 | 1484 | | |
| 1485 | + | |
1462 | 1486 | | |
1463 | 1487 | | |
0 commit comments