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
DM-18576: Warn if translation methods are shadowing others #14
Conversation
This allows people to work out which class triggered the automated method creation.
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.
It's hard for me to wrap my head around the resolution order of things, but it looks right to me.
Raises | ||
------ | ||
AttributeError | ||
Raised if the named method is not defined by this class. |
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 confused here. It states just above that it returns False
if the method is not defined.
Sorry, I see now. If it is not specified in this class specifically, an exception is raised.
@classmethod | ||
def defined_in_class(cls, name): | ||
"""Report if the specified method name is defined in this class | ||
or in a base class. |
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 got tripped up with the wording here. You mean "defined in this class specifically, or instead is defined in one of the classes this class inherits from".
------- | ||
in_class : `bool` | ||
`True` if there is a method of that name defined in this subclass. | ||
`False` if the method is not defined in this specific subclass. |
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.
But is defined in one of the classes this class inherits from.
|
||
for name in both: | ||
if cls.defined_in_class(f"to_{name}"): | ||
# Must be trivial or constant and constant overrides |
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.
This grammar doesn't make a ton of sense to me.
…asses A check is made to see if the method has been defined explicitly in the code before creating a trivial/const version. For this to work properly also needed to prevent parent class definitions of _const_map and _trivial_map from appearing in the class if they weren't explicitly nulled by the class.
It is possible to define a translation method in const_map, trivial_map and explicitly via
def
. Now warn if that is happening. Also if a class was not overriding the trivial/const maps they would get versions from the parent class which could conceivably override the explicit versions in the child. This now does not happen.