Skip to content

[BEAM-3738] Add more flake8 tests to run_pylint.sh#4798

Closed
cclauss wants to merge 1 commit into
apache:masterfrom
cclauss:patch-1
Closed

[BEAM-3738] Add more flake8 tests to run_pylint.sh#4798
cclauss wants to merge 1 commit into
apache:masterfrom
cclauss:patch-1

Conversation

@cclauss

@cclauss cclauss commented Mar 5, 2018

Copy link
Copy Markdown

My sense is that E901,E999,F821,F822,F823 are the "showstopper" flake8 issues that can halt the runtime with a SyntaxError, NameError, etc. The other flake8 issues are merely "style violations" -- useful for readability but they do not effect runtime safety.

This PR therefore recommends replacing --select=E999 with --select=E901,E999,F822,F823 because the codebase currently passes all of these tests and we would like to avoid any backsliding. We would also want to add F821 (undefined names!) to that list but work must be completed on basestring, buffer(), cmp(), file(), reduce(), unicode, xrange(), and #4561 before that can be done.

  • F821: undefined name name
  • F822: undefined name name in __all__
  • F823: local variable name referenced before assignment
  • E901: SyntaxError or IndentationError
  • E999: SyntaxError -- failed to compile a file into an Abstract Syntax Tree

DESCRIPTION HERE


Follow this checklist to help us incorporate your contribution quickly and easily:

  • Make sure there is a JIRA issue filed for the change (usually before you start working on it). Trivial changes like typos do not require a JIRA issue. Your pull request should address just this issue, without pulling in other changes.
  • Format the pull request title like [BEAM-XXX] Fixes bug in ApproximateQuantiles, where you replace BEAM-XXX with the appropriate JIRA issue.
  • Write a pull request description that is detailed enough to understand:
    • What the pull request does
    • Why it does it
    • How it does it
    • Why this approach
  • Each commit in the pull request should have a meaningful subject line and body.
  • Run mvn clean verify to make sure basic checks pass. A more thorough check will be performed on your pull request automatically.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

@aaltay

aaltay commented Mar 6, 2018

Copy link
Copy Markdown
Member

@cclauss

cclauss commented Mar 6, 2018

Copy link
Copy Markdown
Author

Merge #4807 or similar before merging this PR.

Once #4561 and #4806 (or similar) are merged then python2 -m flake8 . --select=F821 should pass but python3 -m flake8 . --select=F821 will require additional work.

@robertwb

robertwb commented Mar 6, 2018

Copy link
Copy Markdown
Contributor

+1 to this direction.

On a higher note, is there a JIRA issue or thread we should be coordinating this work on (or at least referencing).

@cclauss

cclauss commented Mar 6, 2018

Copy link
Copy Markdown
Author

In general, I have been focused on https://issues.apache.org/jira/browse/BEAM-1251

@aaltay

aaltay commented Mar 6, 2018

Copy link
Copy Markdown
Member

@cclauss https://issues.apache.org/jira/browse/BEAM-1251 is an umbrella bug for all python 3 changes. Whenever possible, it makes sense to create sub-issues. Lint for python 3 support should have its own issue at least.

Could you also reference issues in the PR title in the "[BEAM-XYZ] ..." format?

@cclauss cclauss changed the title Update run_pylint.sh [BEAM-3738] Add more flake8 tests to run_pylint.sh Mar 6, 2018
@cclauss

cclauss commented Mar 23, 2018

Copy link
Copy Markdown
Author

Now that #4877 is merged, can we get another review on these changes to avoid backslides? @udim

@udim

udim commented Mar 23, 2018

Copy link
Copy Markdown
Member

retest this please


echo "Running flake8 for module $MODULE:"
flake8 $MODULE --count --select=E999 --show-source --statistics
# TODO: Add F821 (undefined names) as soon as that test passes

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.

Which test passes? Do we have a JIRA tracking this?

Also why F821 is special compared to any other warning to be mentioned in this todo?

@cclauss cclauss Mar 27, 2018

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

All showstopper issue tests pass except for F821 which is what makes it special.

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.

There are other errors/violation codes that are not enabled including F821: http://flake8.pycqa.org/en/latest/user/error-codes.html

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Please reread the first sentence of description above which discusses the "showstopper" flake8 issues vs. the "style violations". I have been focused on the former for the reasons described above.

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.

It is fine to move that sentence to a JIRA, and add a todo referencing that JIRA. People reading that TODO once it is merged would not easily be able to find the PR and understand what is the todo for, and what needs to happen to resolve it.

You can also reference the issues you have noticed with F821 as you mentioned in your other comment in that same JIRA.

@cclauss

cclauss commented Mar 27, 2018

Copy link
Copy Markdown
Author

F821 status (there are PRs open for most of these)...

$ python3 -m flake8 . --count --select=E9,F821,F822,F823 --show-source --statistics

./sdks/python/apache_beam/io/vcfio_test.py:77:14: F821 undefined name 'cmp'
      return cmp(v1.end, v2.end)
             ^
./sdks/python/apache_beam/io/vcfio_test.py:78:12: F821 undefined name 'cmp'
    return cmp(v1.start, v2.start)
           ^
./sdks/python/apache_beam/io/vcfio_test.py:79:10: F821 undefined name 'cmp'
  return cmp(v1.reference_name, v2.reference_name)
         ^
./sdks/python/apache_beam/io/avroio.py:313:34: F821 undefined name 'buffer'
      result = snappy.decompress(buffer(data)[:-4])
                                 ^
./sdks/python/apache_beam/io/gcp/datastore/v1/helper.py:93:12: F821 undefined name 'cmp'
  result = cmp(p1.kind, p2.kind)
           ^
./sdks/python/apache_beam/io/gcp/datastore/v1/helper.py:101:12: F821 undefined name 'cmp'
    return cmp(p1.id, p2.id)
           ^
./sdks/python/apache_beam/io/gcp/datastore/v1/helper.py:106:10: F821 undefined name 'cmp'
  return cmp(p1.name, p2.name)
         ^
./sdks/python/apache_beam/utils/windowed_value.py:196:14: F821 undefined name 'cmp'
      return cmp(type(left), type(right))
             ^
./sdks/python/apache_beam/utils/timestamp.py:100:12: F821 undefined name 'cmp'
    return cmp(self.micros, other.micros)
           ^
./sdks/python/apache_beam/utils/timestamp.py:178:12: F821 undefined name 'cmp'
    return cmp(self.micros, other.micros)
           ^
./sdks/python/apache_beam/testing/test_stream.py:51:14: F821 undefined name 'cmp'
      return cmp(type(self), type(other))
             ^
./sdks/python/apache_beam/testing/test_stream.py:66:12: F821 undefined name 'cmp'
    return cmp(self.timestamped_values, other.timestamped_values)
           ^
./sdks/python/apache_beam/testing/test_stream.py:76:12: F821 undefined name 'cmp'
    return cmp(self.new_watermark, other.new_watermark)
           ^
./sdks/python/apache_beam/testing/test_stream.py:86:12: F821 undefined name 'cmp'
    return cmp(self.advance_by, other.advance_by)
           ^
./sdks/python/apache_beam/transforms/window.py:195:12: F821 undefined name 'cmp'
    return cmp(self.end, other.end) or cmp(hash(self), hash(other))
           ^
./sdks/python/apache_beam/transforms/window.py:195:40: F821 undefined name 'cmp'
    return cmp(self.end, other.end) or cmp(hash(self), hash(other))
                                       ^
./sdks/python/apache_beam/transforms/window.py:250:14: F821 undefined name 'cmp'
      return cmp(type(self), type(other))
             ^
./sdks/python/apache_beam/transforms/window.py:251:12: F821 undefined name 'cmp'
    return cmp((self.value, self.timestamp), (other.value, other.timestamp))
           ^
./sdks/python/apache_beam/runners/portability/fn_api_runner_test.py:103:11: F821 undefined name 'MetricKey'
          MetricKey('mydofn',
          ^
./sdks/python/apache_beam/runners/portability/fn_api_runner_test.py:104:21: F821 undefined name 'MetricName'
                    MetricName('ns1', 'elements')),
                    ^
./sdks/python/apache_beam/runners/portability/fn_api_runner_test.py:105:11: F821 undefined name 'MetricKey'
          MetricKey('myotherdofn',
          ^
./sdks/python/apache_beam/runners/portability/fn_api_runner_test.py:106:21: F821 undefined name 'MetricName'
                    MetricName('ns2', 'elementsplusone'))])
                    ^
./sdks/python/apache_beam/runners/worker/statesampler_slow.py:54:12: F821 undefined name 'StateSamplerInfo'
    return StateSamplerInfo(
           ^
23    F821 undefined name 'buffer'
23

@cclauss

cclauss commented Mar 28, 2018

Copy link
Copy Markdown
Author

@aaltay aaltay 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.

Thank you. I will update the the todo to mention the newly opened JIRA during merge.

@asfgit asfgit closed this in 6b357c6 Mar 28, 2018
@cclauss cclauss deleted the patch-1 branch March 28, 2018 20:25
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.

4 participants