Skip to main content

A flake8 extension that implements misc. lints

Project description

flake8-pie CircleCI pypi

A flake8 extension that implements misc. lints

Note: flake8-pie requires Python 3.6 or greater

lints

  • PIE781: You are assigning to a variable and then returning. Instead remove the assignment and return.
  • PIE782: Unnecessary f-string. You can safely remove the f prefix.
  • PIE783: Celery tasks should have explicit names.
  • PIE784: Celery crontab is missing explicit arguments.
  • PIE785: Celery tasks should have expirations.

PIE781: Assign and Return

Based on Clippy's let_and_return and Microsoft's TSLint rule no-unnecessary-local-variable.

For more info on the structure of this lint, see the accompanying blog post.

examples

# error
def foo():
   x = bar()
   return x

# allowed
def foo():
   x, _ = bar()
   return x

PIE782: No Pointless F Strings

Warn about usage of f-string without templated values.

examples

x = (
    f"foo {y}", # ok
    f"bar" # error
)

PIE783: Celery tasks should have explicit names.

Warn about Celery task definitions that don't have explicit names.

Note: this lint is kind of naive considering any decorator with a .task() method or any decorator called shared_task() a Celery decorator.

examples

# error
@app.task()
def foo():
    pass

# ok
@app.task(name="app_name.tasks.foo")
def foo():
    pass

PIE784: Celery crontab is missing explicit arguments.

The crontab class provided by Celery has some default args that are suprising to new users. Specifically, crontab(hour="0,12") won't run a task at midnight and noon, it will run the task at every minute during those two hours. This lint makes that call an error, forcing you to write crontab(hour="0, 12", minute="*").

Additionally, the lint is a bit more complex in that it requires you specify every smaller increment than the largest time increment you provide. So if you provide days_of_week, then you need to provide hours and minutes explicitly.

Note: if you like the default behavior of crontab() then you can either disable this lint or pass "*" for the kwarg value, e.g., minutes="*".

Also, since this lint is essentially a naive search for calls to a crontab() function, if you have a function named the same then this will cause false positives.

PIE785: Celery tasks should have expirations.

Celery tasks can bunch up if they don't have expirations.

This enforces specifying expirations in both the celery beat config dict and in .apply_async() calls.

The same caveat applies about how this lint is naive.

dev

# install dependencies
poetry install

# install plugin to work with flake8
poetry run python setup.py install

# test
poetry run pytest
# or with watch
poetry run ptw

# typecheck
poetry run mypy *.py

# format
poetry run black .

# lint
poetry run flake8 .

uploading a new version to PyPi

# increment `Flake8PieCheck.version` and pyproject.toml `version`

# build new distribution files and upload to pypi
# Note: this will ask for login credentials
rm -rf dist && poetry publish --build

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flake8-pie-0.4.2.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flake8_pie-0.4.2-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

Details for the file flake8-pie-0.4.2.tar.gz.

File metadata

  • Download URL: flake8-pie-0.4.2.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.11 CPython/3.7.3 Darwin/18.6.0

File hashes

Hashes for flake8-pie-0.4.2.tar.gz
Algorithm Hash digest
SHA256 7e24f7749cc701b0842901b676ca5a4b1c4e3719bcad1192c873dea70b6dee86
MD5 7b8bb3604bff6fbf818607c35966d734
BLAKE2b-256 8316d19a8d1956b5baafc25a4910fa2f20d1ebf0c7aa2fc567d75f43ea76302a

See more details on using hashes here.

File details

Details for the file flake8_pie-0.4.2-py3-none-any.whl.

File metadata

  • Download URL: flake8_pie-0.4.2-py3-none-any.whl
  • Upload date:
  • Size: 11.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.11 CPython/3.7.3 Darwin/18.6.0

File hashes

Hashes for flake8_pie-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f7a821815e60023b9d50d437b97835f44ec15c11a75b20f7f832b7e6e67a7f90
MD5 cea680c73b877d4d7af856dea0c8ac29
BLAKE2b-256 e5f5e80798609837adb73340e96d8611a66b72f2271f334676d5795df2dcdf25

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page