Skip to content

flake8: Enforce E731 (no lambda expressions) on Tests/ - #2019

Merged
peterjc merged 3 commits into
biopython:masterfrom
peterjc:test_lambda
Apr 25, 2019
Merged

peterjc merged 3 commits into
biopython:masterfrom
peterjc:test_lambda

Conversation

@peterjc

@peterjc peterjc commented Apr 19, 2019

Copy link
Copy Markdown
Member

Like #2016 and #2017, this pull request is somewhat related to issue #883 / #2014 and the goal of having universal flake8 settings for the entire project.

  • I hereby agree to dual licence this and any previous contributions under both
    the Biopython License Agreement AND the BSD 3-Clause License.

  • I have read the CONTRIBUTING.rst file and understand that AppVeyor and
    TravisCI will be used to confirm the Biopython unit tests and flake8 style
    checks pass with these changes.

  • I have added my name to the alphabetical contributors listings in the files
    NEWS.rst and CONTRIB.rst as part of this pull request, am listed
    already, or do not wish to be listed. (This acknowledgement is optional.)

@codecov

codecov Bot commented Apr 19, 2019 •

Copy link
Copy Markdown

Codecov Report

Merging #2019 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2019   +/-   ##
=======================================
  Coverage   84.91%   84.91%           
=======================================
  Files         315      315           
  Lines       50544    50544           
=======================================
  Hits        42918    42918           
  Misses       7626     7626

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d533723...11d9fb3. Read the comment docs.

@peterjc

peterjc commented Apr 19, 2019

Copy link
Copy Markdown
Member Author

@MarkusPiotrowski assuming we go ahead with per-folder level settings in a top level .flake8 file as discussed on #2014, do you think this PR is needed?

My opinion was most of the lambda use here was reasonable, my question could be rephrased as: Do we want to strongly discourage using lambdas in future tests?

@MarkusPiotrowski

Copy link
Copy Markdown
Contributor

Actually, I also use lambdas in test_pairwise2. I think tests are somewhat special, where lambdas are useful to quickly setup some conditions that we want to test. So I think it would be OK to ignore E731 for the Tests folder.

@peterjc

peterjc commented Apr 19, 2019

Copy link
Copy Markdown
Member Author

OK, assuming we can ignore F731 with a top level .flake8, I'm happy to close this pull request.

@peterjc

peterjc commented Apr 25, 2019

Copy link
Copy Markdown
Member Author

@MarkusPiotrowski given there seems to be a bug with the flake8 per-file-ignores (see #2014 discussion), shall we go ahead and merge this?

I'll just rebase it now to deal with the merge conflict...

peterjc added 3 commits April 25, 2019 09:27
Quick script used:

import sys

def fix(line):
    if "lambda " not in line:
        return line
    if ":" not in line:
        return line
    if "E731" in line:
        return line
    if line.rstrip().endswith(" \\"):
        # TODO
        return line
    return line.rstrip() + "  # noqa: E731\n"

for f in sys.argv[1:]:
    print(f)
    with open(f) as handle:
        old = list(handle)
    new = [fix(line) for line in old]
    with open(f, "w") as handle:
        for line in new:
            handle.write(line)
print("Done")
@MarkusPiotrowski

Copy link
Copy Markdown
Contributor

OK! Then we need to look at the 28 occurrences of E731 in Bio.

@peterjc
peterjc merged commit b7ff4bd into biopython:master Apr 25, 2019
@peterjc
peterjc deleted the test_lambda branch April 25, 2019 11:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants