-
Notifications
You must be signed in to change notification settings - Fork 81
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
fix: str of KeyError
for <3.11
#2519
Conversation
Codecov Report
Additional details and impacted files
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm uncomfortable about our class pretending to be the builtins.KeyError
. It can be named KeyError
, but let's make it distinguishable by __module__
, so that when someone is digging into a bug, we're not making the solution harder for them.
(I'm assuming that experts who are trying to resolve bugs would know that classes can have the same name in different modules.)
src/awkward/_errors.py
Outdated
# Pretend to be builtins! | ||
AwkwardKeyError.__name__ = "KeyError" | ||
AwkwardKeyError.__qualname__ = "KeyError" | ||
AwkwardKeyError.__module__ = "builtins" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wary of this. It could lead to someone being very confused that this type is not KeyError
for some reason.
I was thinking that we would name the class ak._errors.KeyError
, so it displays its name as KeyError
, but it's distinguishable by its __module__
. Setting __module__ = "builtins"
sounds like we're setting up for a disaster.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fair. In general, it's not good practice to use 'is' like this, but I think you make a reasonable argument. Let's rework this in line with making our error distinguishable from the built-in.
I made a counter-edit to indicate what I meant. If we're saying its name is It means that we can never use unqualified |
elif issubclass(cls, builtins.KeyError): | ||
new_exception = KeyError(self.format_exception(exception)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer not to shadow the KeyError
builtin, as it's not something one usually overrides in a global namespace. Our AwkwardKeyError
isn't something I anticipated even L3 awkward modules importing, so changing __name__
didn't both me. With some time having elapsed, I have changed my mind on that, so I'm now in favour of this change.
This fixes #2513