Skip to main content

Enforce Newspaper Style with Flake

Motivation

Good code reads like a newspaper. Start with the highest abstraction, go to the details. This also enables to read the code without an editor.

Quoting Robert C. Martin from his Clean Code book.

“Think of a well-written newspaper article. You read it vertically. At the top you expect a headline that will tell you what the story is about and allows you to decide whether it is something you want to read. The first paragraph gives you a synopsis of the whole story, hiding all the details while giving you the broad-brush concepts. As you continue downward, the details increase until you have all the dates, names, quotes, claims, and other minutia.”

In Python newspaper code should look like this.

def headline():
    text()

def text():  # this needs to be defined after the usage.
    ...

There hasn't been an automatic way in python to check for this. So here it is.

Usage

# install the flake8 extension for newspaper style
pip3 install flake8-newspaper-style==0.4.2
# then check your code
flake8 --select=NEW src  # here it restricts flake8 to newspaper style issues

References

Metadata

Release files for flake8-newspaper-style 0.4.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for flake8-newspaper-style 0.4.3
File Size Uploaded Provenance
flake8-newspaper-style-0.4.3.tar.gz 4.5 kB Without provenance Details

Release files / flake8-newspaper-style-0.4.3.tar.gz

Download URL flake8-newspaper-style-0.4.3.tar.gz
Size 4.5 kB
Tags Source
SHA-256 checksum
How to use checksums
d05924256cb9992eb61d3718c7301bc8f3b2a847f159b5f9e25a508261359974
BLAKE2b-256 checksum
How to use checksums
2b3fc43be62fb54b5b1d22954aceeefe9bf1a7238d9b6f36d811ed6f363067af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.14

Security for flake8-newspaper-style 0.4.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page