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.

overzealous removal of noqa: E402

See original GitHub issue

Given this setup

$ cat .pre-commit-config.yaml

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
  rev: v2.0.0
  hooks:
  - id: flake8
    additional_dependencies:
    - flake8==3.6.0
- repo: https://github.com/asottile/yesqa
  rev: v0.0.8
  hooks:
  - id: yesqa
    additional_dependencies:
    - flake8==3.6.0

$ cat example.py

import gevent.monkey
gevent.monkey.patch_all()

from datetime import datetime

print(gevent.spawn(lambda: datetime.now()).get())

Then pre-commit run flake8 --files example.py fails with

Flake8...................................................................Failed
hookid: flake8

example.py:4:1: E402 module level import not at top of file

This is expected. However if I change line 2 (not the reported line 4) to be:

- gevent.monkey.patch_all()
+ gevent.monkey.patch_all()  # noqa: E402

Then flake8 passes, but yesqa will rewrite the file and remove the noqa, causing flake8 to fail again.

Should yesqa instead keep that noqa? Or should I noqa: E402 line 4 and any other possible imports I add in the future?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
asottilecommented, May 14, 2020

flake8 3.8 has been released so the behaviour here is now consistent

0reactions
asottilecommented, Nov 19, 2018

probably add special casing in yesqa for E402. The eventual long-term northstar is to make flake8 error on noqa that doesn’t apply but I think that’s pretty far off

Read more comments on GitHub >

github_iconTop Results From Across the Web

What does '# noqa' mean in Python comments? - Stack Overflow
noqa most likely stands for no quality assurance . It tells code-analysis software to ignore warnings. – Stevoisiak. Jan 30, 2018 at 17:23....
Read more >
Text - Python mailing list
+ """ > + match = not noqa and COMPARE_SINGLETON_REGEX.search(logical_line) > + if match: ... + > + The older syntax is removed...
Read more >
OpenStack: ChangeLog - Fossies
As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers.
Read more >
app-admin - Gentoo
-rw-r--r--, app-admin/elektra/files/elektra-0.7.1-remove-ddefault-link.patch, 16 ... +-# flake8: noqa: E402. +-from ansible.module_utils.common.yaml import ...
Read more >
将源码从旧仓库迁移到新仓库中 · db10ea6e93 - 代码服务器
+ URLs, and so have had parameters added. This was removed in v2.12.2 in an. + overzealous attempt to resolve problems with IDNA-encoding...
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