Bug report
Bug description:
I have encountered a problem when using the __getitem__ method in cpython 3.10.12 and 3.15.0a0:
When a class has a __getitem__ but not a __contains__ method python seems to brute force the key when using the keyword in. I know this must be intentional (brute forcing does not happen by accident). But in the code, i encountered this in, i was using strings as keys, which python will never brute force. In this case it will never return. From a users perspective it would be more helpful to have a clear error message instead.
class test:
def __init__(self):
pass
def __getitem__(self, key):
print(key)
if "this is a test" in test():
print("it is in it?")
this will count up to infinity!
I hope this will not drown among the 7000 Issues.
Thanks for reviewing this and God Bless you!
CPython versions tested on:
3.15, CPython main branch, 3.10
Operating systems tested on:
Linux
Bug report
Bug description:
I have encountered a problem when using the
__getitem__method in cpython 3.10.12 and 3.15.0a0:When a class has a
__getitem__but not a__contains__method python seems to brute force the key when using the keywordin. I know this must be intentional (brute forcing does not happen by accident). But in the code, i encountered this in, i was using strings as keys, which python will never brute force. In this case it will never return. From a users perspective it would be more helpful to have a clear error message instead.this will count up to infinity!
I hope this will not drown among the 7000 Issues.
Thanks for reviewing this and God Bless you!
CPython versions tested on:
3.15, CPython main branch, 3.10
Operating systems tested on:
Linux