You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So, while __contains__ is well intercepted, this is not the case for __getitem__.
I wonder if this is something that is missing in forbiddenfruit or if this is something related to the language.
Best,
christophe
The text was updated successfully, but these errors were encountered:
This is related to the language - in many areas of the CPython codebase, "shortcuts" are being made if strict type checks match.
For example, this is the implementation of BINARY_SUBSCR - the opcode implementing x[y] - for CPython v2.7.18. You can clearly see that it has special treatment for lists - objects that match PyList_CheckExact(o), which is equivalent to type(o) is list. COMPARE_OP (in) which implements x in y does not have shortcuts for lists, therefore "it works" for you.
In recent CPython versions I don't see the code in ceval.c implementing the shortcut for subscripting, so it might have been moved somewhere else down the call chain, or removed completely. Generally, while forbiddenfruit allows for it, depending on overriding of basic operators of builtin types is not consistent across CPython versions. AFAIK, these things can change.
Hi,
Thank you for your useful module.
In my case, I would like to override
__getitem__
, but that does not seems to be working.I have installed forbiddenfruit 0.1.3 and I run python 3.5.2.
For the following piece of code (test.py):
I obtain (python3 test.py):
So, while
__contains__
is well intercepted, this is not the case for__getitem__
.I wonder if this is something that is missing in forbiddenfruit or if this is something related to the language.
Best,
christophe
The text was updated successfully, but these errors were encountered: