Skip to content
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

Merged
merged 3 commits into from Mar 22, 2019

Conversation

timj
Copy link
Member

@timj timj commented Mar 21, 2019

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.

This allows people to work out which class triggered the
automated method creation.
@timj timj requested a review from SimonKrughoff March 21, 2019 17:08
Copy link
Contributor

@SimonKrughoff SimonKrughoff left a 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.
Copy link
Contributor

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.
Copy link
Contributor

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.
Copy link
Contributor

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
Copy link
Contributor

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.
@timj timj merged commit 4569f62 into master Mar 22, 2019
@timj timj deleted the tickets/DM-18576 branch March 22, 2019 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants