Skip to content

How to make peace with needed nested import statements for Ruff E402? #9091

@alanwilter

Description

@alanwilter

I use this lines a lot in several projects.

import matplotlib
import numpy as np

matplotlib.use("Agg")

from matplotlib import pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages

There's no other way that I know to set the matplotlib backend. But by doing so this will trigger E402.

isort has some ways of handling that (see here).

Of course I can fill lots of # noqa: E402 but this is so ugly.

Ideally, Ruff/isort should be smart enough to know these cases.

Also, perhaps, page E402 (and all others when reasonable) should show how to silence this warning if the user knows what's doing.

Metadata

Metadata

Assignees

Labels

ruleImplementing or modifying a lint rule

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions