Commit 7663646
committed
Compare intercepted attribute names by value, not only by identity.
The C extension intercepts __module__ and __doc__ in the attribute get
and set slots of the base object proxy, and __signature__ in the get slot
of PartialCallableObjectProxy, by comparing the name against an interned
string held in module state. That comparison was by identity only, so it
relied on the incoming name having been interned. Names originating from
Python source code always are, but a name constructed at runtime, for
example by string concatenation or decoding, is not, and for such a name
the interception was silently skipped. Getting __module__ or __doc__ then
returned the copy captured in the instance dict when the proxy was
created rather than the current value on the wrapped object, setting them
stored the value on the proxy instead of the wrapped object, and
__signature__ was forwarded to the wrapped callable.
Add a wrapt_name_equals() helper which keeps the identity comparison as
the fast path and falls back to a value comparison, guarded by a length
check so that the cost for non matching names is a single integer
comparison, following the pattern CPython uses in super_getattro(). Use
it at all three sites and add tests exercising each attribute with a
non interned name.1 parent 5fc1e3f commit 7663646
4 files changed
Lines changed: 104 additions & 5 deletions
File tree
- docs
- src/wrapt
- tests/core
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
41 | 54 | | |
42 | 55 | | |
43 | 56 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
205 | 205 | | |
206 | 206 | | |
207 | 207 | | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
208 | 237 | | |
209 | 238 | | |
210 | 239 | | |
| |||
3336 | 3365 | | |
3337 | 3366 | | |
3338 | 3367 | | |
3339 | | - | |
| 3368 | + | |
3340 | 3369 | | |
3341 | | - | |
| 3370 | + | |
3342 | 3371 | | |
3343 | 3372 | | |
3344 | 3373 | | |
| |||
3418 | 3447 | | |
3419 | 3448 | | |
3420 | 3449 | | |
3421 | | - | |
| 3450 | + | |
3422 | 3451 | | |
3423 | | - | |
| 3452 | + | |
3424 | 3453 | | |
3425 | 3454 | | |
3426 | 3455 | | |
| |||
4071 | 4100 | | |
4072 | 4101 | | |
4073 | 4102 | | |
4074 | | - | |
| 4103 | + | |
4075 | 4104 | | |
4076 | 4105 | | |
4077 | 4106 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
205 | 205 | | |
206 | 206 | | |
207 | 207 | | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
208 | 224 | | |
209 | 225 | | |
210 | 226 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
325 | 325 | | |
326 | 326 | | |
327 | 327 | | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
328 | 369 | | |
329 | 370 | | |
0 commit comments