-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UserDict __getitem__
behavior change between 3.11.1 and 3.12.0b2
#105524
Comments
This also reproduced on the current main. |
Also, if you define a Introduced in #17910 |
IUUC, the proposed fix is to change the implementation to the following: import collections
class DotDict(collections.UserDict):
def __getitem__(self, key):
subitem = self.data
for subkey in key.split("."):
try:
subitem = subitem[subkey]
except KeyError:
raise KeyError(f"`{key}` not found in configuration") from None
return subitem
def __contains__(self, key):
subitem = self.data
for subkey in key.split("."):
try:
subitem = subitem[subkey]
except KeyError:
return False
return True Not ideal, but it works. |
This also affects me. |
I define the following UserDict, that implements nested lookups (
d['key.subkey']
):I expect the following to work as it did in Python 3.11, but it does not:
I do not see any release notes indicating that
__getitem__
is no longer the correct method to override.The text was updated successfully, but these errors were encountered: