question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Running nbqa with flake8 complains about blank lines on notebook cells with functions

See original GitHub issue

Consider a cell containing a function

# cell contents
def get_dataset():
    return make_classification(
        n_samples=1000, n_features=20, n_informative=15, n_redundant=5, random_state=7
    )

I am getting the warnings

  • E302 expected 2 blank lines, found 1.
  • E305 expected 2 blank lines after class or function definition, found 1

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
MarcoGorellicommented, Oct 5, 2020

I’m not sure how we could consistently put the correct number of blank lines between cells…I’m tempted to just have a “suggested configs” document in which we suggest which errors to ignore for which tools. Or do you think this is solvable?

0reactions
girip11commented, Oct 5, 2020

After the split, we can strip \n from the cell content

yes but if isort makes any changes, then won’t it (potentially) return the wrong exit code? e.g. like this it could happen that you run nbqa isort notebook.ipynb and you get

fixing notebook.ipynb

but then if you do git diff you see that nothing has changed

Great point. I didn’t think isort would change the file when no imports has to be sorted.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Verifying PEP8 in iPython notebook code - Stack Overflow
first load the magic in a Jupyter Notebook cell: ... seems to always have a "blank line at end of file", so I...
Read more >
Configuration — nbQA 1.5.3 documentation - Read the Docs
You can configure nbQA either at the command line, or by using a pyproject.toml file. ... nbqa black my_notebook.ipynb --nbqa-process-cells add_to.
Read more >
Linters — Using Automation To Support Quality Assured ...
Code in notebook code cells can be linted using various tools including ... enabled when flake8 is run from the command line, either...
Read more >
We're the core team behind the popular Python autoformatter
Black allows you to write your Python code however you like, ... above a function definition, in that flake8 counts the comment as...
Read more >
flake8-nb - PyPI
Flake8 based checking for jupyter notebooks. ... nbQA: Run isort, pyupgrade, mypy, pylint, flake8, mdformat, black, blacken-docs, and more on Jupyter ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found