Skip to content

PDBList local_dtd bug and other minor flake8-bugbear issues - #1728

Merged
peterjc merged 3 commits into
biopython:masterfrom
peterjc:flake8-bugbear
Aug 17, 2018
Merged

peterjc merged 3 commits into
biopython:masterfrom
peterjc:flake8-bugbear

Conversation

@peterjc

@peterjc peterjc commented Jul 6, 2018

Copy link
Copy Markdown
Member

This pull request addresses some minor issues noticed from running flake8-bugbear,

https://github.com/PyCQA/flake8-bugbear

I have ignored all the B007 warnings about loop variable names, and there are still 8 cases of B008 but they looked harmless.

Building on this, we could enable these checks on TravisCI (ignoring B007 and whitelisting the current B008 cases)?

  • 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.)

peterjc added 3 commits July 6, 2018 11:49
These two uses are Python 2 specific and thus appropriate.
This avoids a flake8-bugbear warning,

B008 Do not perform calls in argument defaults. The call is performed only once at function definition time. All calls to your function will reuse the result of that definition-time call. If this is intended, assign the function call to a module-level variable and use that variable as a default value.

We already have a module-level variable with a shared
instance of the generic protein alphabet - so use that.
Previously default would be the current directory at the
time of the import:

$ python -c "import os; print(os.getcwd()); from Bio.PDB.PDBList import PDBList; os.chdir('/tmp'); print(PDBList().local_pdb); os.chdir('/Users/peter/'); print(PDBList().local_pdb)"
/Users/peter/repositories/biopython
/Users/peter/repositories/biopython
/Users/peter/repositories/biopython

Now:

$ python -c "import os; print(os.getcwd()); from Bio.PDB.PDBList import PDBList; os.chdir('/tmp'); print(PDBList().local_pdb); os.chdir('/Users/peter/'); print(PDBList().local_pdb)"
/Users/peter/repositories/biopython
/private/tmp
/Users/peter

Spotted via flake8-bugbear,

Bio/PDB/PDBList.py:86:58: B008 Do not perform calls in argument defaults. The call is performed only once at function definition time. All calls to your function will reuse the result of that definition-time call. If this is intended, assign the function call to a module-level variable and use that variable as a default value.
@peterjc
peterjc requested a review from etal July 6, 2018 11:13
@peterjc
peterjc requested a review from JoaoRodrigues as a code owner July 6, 2018 11:13
@codecov

codecov Bot commented Jul 6, 2018 •

Copy link
Copy Markdown

Codecov Report

❗ No coverage uploaded for pull request base (master@2afe4ec). Click here to learn what that means.
The diff coverage is 50%.

Impacted file tree graph

@@           Coverage Diff            @@
##             master   #1728   +/-   ##
========================================
  Coverage          ?   85.6%           
========================================
  Files             ?     327           
  Lines             ?   50082           
  Branches          ?       0           
========================================
  Hits              ?   42872           
  Misses            ?    7210           
  Partials          ?       0
Impacted Files Coverage Δ
Bio/SeqIO/UniprotIO.py 92.21% <100%> (ø)
Bio/PDB/PDBList.py 16.45% <25%> (ø)
Bio/SearchIO/_model/query.py 92.43% <50%> (ø)

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 2afe4ec...5f61d81. Read the comment docs.

@peterjc
peterjc merged commit b1440a5 into biopython:master Aug 17, 2018
@peterjc
peterjc deleted the flake8-bugbear branch August 17, 2018 12:46
@peterjc

peterjc commented Aug 17, 2018

Copy link
Copy Markdown
Member Author

TravisCI use of flake8-bugbear enabled in 0de46ac

peterjc added a commit to peterjc/biopython that referenced this pull request Aug 24, 2018
Closes biopython#1515, thanks to work in pull request biopython#1748
and pull request biopython#1728.
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.

1 participant