Repository navigation
Commit 5488b77
committed
BUG: fix str_ and bytes_ scalars not supporting [()] indexing
numpy.str_ and numpy.bytes_ inherit Python's str.__getitem__ and
bytes.__getitem__, which intercept [()] (empty tuple) before NumPy's
0-d scalar indexing protocol, raising TypeError instead of returning
the scalar value.
Fix by adding a custom tp_as_mapping slot with stringtype_subscript
that intercepts the empty-tuple case via .item(), and delegates all
other keys to the generic 0-d array subscript path (PyArray_FromScalar
+ array_subscript) — the same pattern used by voidtype_subscript in
scalartypes.c.src.
Fixes: numpy#31435
Signed-off-by: Mohataseem Khan <[email protected]>1 parent 9721c24 commit 5488b77
1 file changed
Lines changed: 23 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4217 | 4217 | | |
4218 | 4218 | | |
4219 | 4219 | | |
4220 | | - | |
| 4220 | + | |
4221 | 4221 | | |
4222 | | - | |
4223 | | - | |
4224 | | - | |
4225 | | - | |
4226 | | - | |
4227 | | - | |
4228 | | - | |
4229 | | - | |
4230 | | - | |
4231 | | - | |
4232 | | - | |
4233 | | - | |
4234 | | - | |
4235 | | - | |
4236 | | - | |
4237 | | - | |
| 4222 | + | |
| 4223 | + | |
| 4224 | + | |
| 4225 | + | |
| 4226 | + | |
| 4227 | + | |
| 4228 | + | |
4238 | 4229 | | |
| 4230 | + | |
| 4231 | + | |
4239 | 4232 | | |
4240 | 4233 | | |
4241 | 4234 | | |
| 4235 | + | |
| 4236 | + | |
| 4237 | + | |
| 4238 | + | |
| 4239 | + | |
| 4240 | + | |
4242 | 4241 | | |
4243 | 4242 | | |
4244 | 4243 | | |
| |||
4267 | 4266 | | |
4268 | 4267 | | |
4269 | 4268 | | |
4270 | | - | |
| 4269 | + | |
4271 | 4270 | | |
4272 | 4271 | | |
4273 | 4272 | | |
| |||
4492 | 4491 | | |
4493 | 4492 | | |
4494 | 4493 | | |
| 4494 | + | |
| 4495 | + | |
4495 | 4496 | | |
4496 | 4497 | | |
4497 | 4498 | | |
| 4499 | + | |
| 4500 | + | |
| 4501 | + | |
| 4502 | + | |
4498 | 4503 | | |
4499 | 4504 | | |
4500 | 4505 | | |
| |||
0 commit comments