Skip to content

noqa

Syntax: inline comment — not a pyproject.toml setting Scope: line-level or file-level


Description

# noqa: pap: comments let you suppress violations inline, directly in your Python source code — without touching pyproject.toml.

Use noqa for specific, justified exceptions: generated files, known false positives, or patterns your team has consciously accepted in one place. For broader suppression across the whole codebase, use ignore or warn in pyproject.toml instead.


Line-level suppression

Suppress one or more rules on a single line:

result = df.collect()  # noqa: pap: D001

Suppress multiple rules on the same line with a comma-separated list:

bad_join = df.crossJoin(other)  # noqa: pap: S010, S002

Suppress all pap rules on a line (use sparingly):

df = df.withColumn("x", expr("a+b"))  # noqa: pap

The comment must be on the same line as the violation. A # noqa on the line above or below has no effect.


File-level suppression

To suppress every violation in an entire file, add # noqa: pap: FILE anywhere in the file — typically at the top:

# noqa: pap: FILE
# This file is auto-generated by codegen.py — do not edit by hand.

from pyspark.sql import functions as F

def build_report(df):
    return df.collect()  # would normally fire D001

The FILE keyword can appear on any line, but placing it at the top makes intent obvious. It is often the right choice for:

  • Auto-generated files that are not maintained by hand
  • Migration scripts with intentional one-off patterns
  • Vendored or third-party code copied into the repo

Warning

File-level suppression silences all pap rules in the file — including rules that may indicate genuine performance problems. Prefer line-level suppression when only a subset of violations should be ignored.


Precedence

noqa takes effect after all other filters (ignore, warn, select, severity, pyspark_version). A violation that is already ignored by pyproject.toml settings will never reach the noqa filter — noqa is only relevant for violations that would otherwise be reported.


Comparison with pyproject.toml settings

Mechanism Scope Where
ignore = [...] All files, all occurrences pyproject.toml
warn = [...] All files, all occurrences pyproject.toml
# noqa: pap: RULE One specific line Source file
# noqa: pap All rules on one line Source file
# noqa: pap: FILE Entire file Source file

Examples

Suppress a single rule on one line

# D001 fires here because .collect() loads the full dataset to the driver.
# In this test helper, that is intentional — the data is tiny and local.
rows = df.collect()  # noqa: pap: D001

Suppress multiple rules on one line

# S010 (crossJoin) and S002 (join without hint) both fire here.
# This is a deliberate cartesian product in a small-data reporting query.
report = dim.crossJoin(fact)  # noqa: pap: S010, S002

Suppress all rules on one line

legacy_rdd = df.rdd.map(lambda r: r["key"])  # noqa: pap

Suppress an entire generated file

# noqa: pap: FILE
# Auto-generated by tools/generate_schema.py
# Do not edit — run `make generate` to regenerate.

from pyspark.sql.types import StructType, StructField, StringType, LongType

SCHEMA = StructType([...])