# flake8: noqa inside a string literal skips the whole file
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 76/100
Direzione di ricerca
Start in FileProcessor.should_ignore_file and inspect how defaults.NOQA_FILE is matched against raw source lines; compare this with tokenize.COMMENT handling and the related Violation.is_inline_ignored path. Reproduce the fn.py example, then verify that a directive inside a docstring no longer skips the file while real F401, E201, and E225 violations are still reported.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
# flake8: noqa inside a string literal causes the whole file to be skipped, so a file with real violations is reported clean and flake8 exits 0.
Steps to reproduce
Save as fn.py:
"""Our lint configuration for this module.
Reproduce with:
flake8 --isolated
Suppress with:
# flake8: noqa
"""
import os
def f( ):
x=1
return os, x
$ flake8 fn.py; echo "exit=$?"
exit=0
$ flake8 --disable-noqa fn.py
fn.py:12:1: F401 'os' imported but unused
...
exit=1
The real F401, E201 and E225 are all there — a # noqa: F401 on a code line, or a comment elsewhere in the file, does not suppress them. Only this one, which is string content.
It also happens with a docstring on a nested function, and with any triple-quoted string containing a line that starts with the directive.
Why this matters more than a normal false positive
The file reports clean and the exit status is 0, so CI passes on a file that has violations. The E/W/F/C checks never get a chance to run — the decision is made before any plugin sees the file.
Cause
FileProcessor.should_ignore_file regex-matches defaults.NOQA_FILE against the raw source lines, so it cannot tell a comment from string content. The docstring above is the most natural place to write down a file's own lint configuration, and the directive ends up on a line by itself inside it.
This is a residual of #873 ("Only skip a file if # flake8: noqa is on a line by itself"). That change switched .search to .match, which fixed the trailing-comment case but not a standalone line inside a docstring.
Suggested fix
Match only lines that carry a tokenize.COMMENT token, falling back to all lines when the file cannot be tokenized. This is the same remedy asottile described for the inline directive in #1321 — "I think the regex is still relevant but it should only be tested against COMMENT tokens" — applied to the file-level directive, which is a different function (FileProcessor.should_ignore_file, not Violation.is_inline_ignored).
If you would rather do the tokenization rework for both at once, this is happy to be folded into that.
Related, separate
defaults.NOQA_FILE is re.compile(r"\s*# flake8[:=]\s*noqa", re.I) with no end anchor, so a line reading # flake8: noqaX also skips the whole file. That is a different question and not claimed here.
- Lingua principale
- Python
- Stelle
- 3.8k
- Fork
- 363
- Merge medio
- 3h 59m
- PR unite (30g)
- 11
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di PyCQA/flake8
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
PyCQA/flake8#2062 · 4 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Max Line Length in style guide ignored with python 3.14 when checking multiple filesForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
PyCQA/flake8#2011 · 5 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
PyCQA/flake8#1793 · 9 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 42/100
PyCQA/flake8#1774 · 13 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
option_manager.add_option ignores action when reading from configForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
PyCQA/flake8#1770 · 5 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di PyCQA/flake8
Issue simili
-
Pull-through from gcr.io returns 500 when pulling using podman/buildahForse già presa Una pull request collegata a questa issue è aperta o già unita. ApertaIssue Triage-Needed
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
pulp/pulp_container#2581 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
521xueweihan/HelloGitHub#4040 ·
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
ClanGenOfficial/clangen#6313 ·
I maintainer di solito rispondono entro 2 giorni
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
I maintainer di solito rispondono entro 1 giorno
-
bug(trainer): CustomTrainer func_args with non literal values fail inside the TrainJobForse già presa @avanishkasar l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
kubeflow/sdk#879 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno