Skip to content

STYLE use subprocess to validate flake8 on docstrings instead of Application #40784

Closed
@MarcoGorelli

Description

@MarcoGorelli

According to flake8's creator, the Application class from flake8 isn't meant to be used a library. As their sole maintainer isn't the original author, the library's internals could well change without warning, and this would break scripts/validate_docstrings.

This part probably wants changing:

application = flake8.main.application.Application()
application.initialize(["--quiet"])
with tempfile.NamedTemporaryFile(mode="w", encoding="utf-8") as file:
file.write(content)
file.flush()
application.run_checks([file.name])
# We need this to avoid flake8 printing the names of the files to
# the standard output
application.formatter.write = lambda line, source: None
application.report()
yield from application.guide.stats.statistics_for("")

We're already writing the docstring to a temporary file, so we could just run flake8 on that via subprocess.run

Metadata

Metadata

Assignees

Labels

Code StyleCode style, linting, code_checks

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions