Skip to content

[tools] Enable additional linting rules - #11110

Merged
gsnedders merged 5 commits into
web-platform-tests:masterfrom
bocoup:more-linting
May 24, 2018
Merged

gsnedders merged 5 commits into
web-platform-tests:masterfrom
bocoup:more-linting

Conversation

@jugglinmike

@jugglinmike jugglinmike commented May 23, 2018 •

Copy link
Copy Markdown
Contributor

This change is Reviewable

@Hexcles Hexcles left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Custom has_key methods are defined in wptrunner/wptrunner/wptmanifest/backends/{conditional,static}.py
which is why unit tests are failing with your changes. The methods probably need to be renamed to the magic __contains__.

@jugglinmike

Copy link
Copy Markdown
Contributor Author

Thanks for the tip, @Hexcles! Unfortunately, enabling this linting option might take a little more work. That's because the "conditional" ManifestItem already defines a __contains__ method:

    def __contains__(self, key):
        return key in self._data

And its semantics are distinct from those of the custom has_key method

    def has_key(self, key):
        for node in [self, self.root]:
            if key in node._data:
                return True
        return False

There may be a case to be made against an API where x.has_key(x) behaves differently than str in x and that perhaps has_key should be renamed to more clearly signal the advanced lookup logic it implements. However, that discussion and that level of change are more than I really meant to start with this patch. I'm more inclined to remove the second commit and worry about has_key when/if we decide to take on the much larger (and more meaningful) task of supporting Python 3.

What do you think?

@Hexcles

Hexcles commented May 23, 2018

Copy link
Copy Markdown
Member

We should probably rename has_key. Clashing with a deprecated built-in method name is not good.

That said, I haven't looked too closely at the related code. If you're not sure what to do, then we can always make a smaller step each time (i.e. abandon the second and third commits for now).

@gsnedders

Copy link
Copy Markdown
Member

@jgraham objected to renaming has_key before, fwiw.

@jugglinmike

Copy link
Copy Markdown
Contributor Author

@gsnedders In that case, we should definitely proceed with that change in a separate patch. Thanks for letting us know!

@jgraham In can't find anything about your objection on GitHub or the #testing IRC logs. Would you mind re-iterating here?

@Hexcles I've reverted the commits related to that rule. This should be good to go now.

@Hexcles Hexcles left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r+

@gsnedders
gsnedders merged commit ba7899b into web-platform-tests:master May 24, 2018
@jugglinmike

Copy link
Copy Markdown
Contributor Author

Thanks, @gsnedders!

@jugglinmike

Copy link
Copy Markdown
Contributor Author

Oh and @Hexcles of course :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants