Skip to content

Auto flake #1741

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

Closed
wants to merge 6 commits into from
Closed

Auto flake #1741

wants to merge 6 commits into from

Conversation

mrocklin
Copy link
Contributor

@mrocklin mrocklin commented Nov 23, 2017

  • Closes #xxxx
  • Tests added / passed
  • Passes flake8 xarray
  • Fully documented, including whats-new.rst for all changes and api.rst for new API

I had a free half hour so I decided to run autoflake and autopep8 tools on the codebase. flake8 xarray passes. I copied over the exclusions that we use within dask/distributed and extended the line length to 120. You may wish to review these decisions.

autoflake --in-place xarray/*.py xarray/*/*.py
autopep8 --in-place --max-line-length 120 --global-config setup.cfg xarray/*.py xarray/*/*.py
@@ -203,11 +203,11 @@ def test_sizes(self):
def test_encoding(self):
expected = {'foo': 'bar'}
self.dv.encoding['foo'] = 'bar'
assert expected, self.d == encoding
assert expected == self.dv.encoding
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change was odd. I'm not sure what was expected here.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I think this change is correct. I have no idea what was going on previously -- self.d is not even a valid attribute.

Copy link
Contributor

Choose a reason for hiding this comment

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

Previously, it asserted that expected was true-ish; if it wasn’t, it would print the value of self.d == encoding as the message, but that expression is only evaluated if the assert fails.

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean, that’s how the code was able to pass without error. Not sure what happened to cause that to be written. 😁

@mrocklin
Copy link
Contributor Author

I'm not sure how to fix these lines in xarray/tests/test_computation.py::test_keep_attrs

a = xr.Dataset({'x': ('x', [1, 2]), 'x': [0, 1]})
b = xr.Dataset({'x': ('x', [1, 1]), 'x': [0, 1]})

We're reusing the same key, 'x', twice

@shoyer
Copy link
Member

shoyer commented Nov 25, 2017

@mrocklin oof, you're catching all our questionable code!

Try xr.Dataset({'x': [1, 2]}) for both of these.

Copy link
Member

@shoyer shoyer left a comment

Choose a reason for hiding this comment

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

Thanks!

@@ -203,11 +203,11 @@ def test_sizes(self):
def test_encoding(self):
expected = {'foo': 'bar'}
self.dv.encoding['foo'] = 'bar'
assert expected, self.d == encoding
assert expected == self.dv.encoding
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I think this change is correct. I have no idea what was going on previously -- self.d is not even a valid attribute.

E731,
# Ambiguous variable names
E741
max-line-length = 120
Copy link
Member

Choose a reason for hiding this comment

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

Let's leave this as the default (79 per PEP8)

@fujiisoup fujiisoup mentioned this pull request Nov 29, 2017
4 tasks
Copy link
Member

@jhamman jhamman left a comment

Choose a reason for hiding this comment

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

@mrocklin - I'm glad you did this. I'd suggest not letting this linger as you're bound to end up with a million little merge conflicts. @shoyer recommended one change but other than that, this looks good.

@@ -91,7 +91,7 @@ install:
script:
- python -OO -c "import xarray"
- py.test xarray --cov=xarray --cov-config ci/.coveragerc --cov-report term-missing --verbose $EXTRA_FLAGS
- git diff upstream/master **/*py | flake8 --diff --exit-zero || true
- flake8 -j auto xarray
Copy link
Member

Choose a reason for hiding this comment

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

question: do we want to have travis fail when flake8 finds something awry?

Copy link
Contributor

Choose a reason for hiding this comment

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

IMO yes; it's the only way to keep flake8 passing.

Copy link
Contributor

@Zac-HD Zac-HD left a comment

Choose a reason for hiding this comment

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

Generally LGTM, and I think linting everything is a great direction to move in.

However - changing the Travis command and adding exclusions to the config allows us to go backwards as new code is added with warnings that were not previously ignored. See comment below on an alternative approach.

@@ -91,7 +91,7 @@ install:
script:
- python -OO -c "import xarray"
- py.test xarray --cov=xarray --cov-config ci/.coveragerc --cov-report term-missing --verbose $EXTRA_FLAGS
- git diff upstream/master **/*py | flake8 --diff --exit-zero || true
- flake8 -j auto xarray
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO yes; it's the only way to keep flake8 passing.

@@ -91,7 +91,7 @@ install:
script:
- python -OO -c "import xarray"
- py.test xarray --cov=xarray --cov-config ci/.coveragerc --cov-report term-missing --verbose $EXTRA_FLAGS
- git diff upstream/master **/*py | flake8 --diff --exit-zero || true
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of replacing this, I'd actually enforce that the diff must be flake8-clean:

git diff master **/*py | flake8 --diff

And then add a second check that covers all files but ignores some errors in existing code:

flake8 --ignore E20,E231,E241,E26,E4,E721,E731,E741 xarray

Which means that the config section can (needs to be) be left as-is.

@Zac-HD Zac-HD mentioned this pull request Jan 13, 2018
@shoyer shoyer closed this in #1824 Jan 14, 2018
@Zac-HD Zac-HD mentioned this pull request Feb 28, 2018
1 task
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.

5 participants