Skip to main content

An extension for flake8 that forbids some functions in some modules.

Project description

flake8-forbidden-func

An extension for flake8 that forbids some functions in some modules.

Installation

pip install flake8-forbidden-func

Example

# users/views.py
from users import User
import datetime


def test_view():
    print(datetime.datetime.now())
    faz = User.objects.all().annotate().filter(a=2)
    baz = bar_func()

    if faz == baz:
        fuz = q.filter(a=1)
        return fuz.bar()
# setup.cfg
[flake8]
forbidden-functions =
    *.views: *.filter, views module should not use ORM filter
    *: datetime.datetime.now, we use django utils
allowed-functions =
    *.selectors: *.objects.*, only selectors module should use ORM

Usage:

$ flake8 users/views.py
users/views.py:6:11: CFF001 datetime.datetime.now call is forbidden,since we use django utils.
users/views.py:7:11: CFF001 *.objects.* call is forbidden, since only selectors module should use ORM.
users/views.py:7:11: CFF001 *.objects.* call is forbidden, since only selectors module should use ORM.
users/views.py:7:11: CFF001 *.objects.* call is forbidden, since only selectors module should use ORM.
users/views.py:11:15: CFF001 *.filter call is forbidden, since views module should not use ORM filter.

Tested on Python 3.7+ and flake8 4.0+.

Error codes

Error code Description
CFF001 call is forbidden, since reason
CFF000 happens when we get unhandled exception during the linting process

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_forbidden_func-0.1.0.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

flake8_forbidden_func-0.1.0-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file flake8_forbidden_func-0.1.0.tar.gz.

File metadata

  • Download URL: flake8_forbidden_func-0.1.0.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.0

File hashes

Hashes for flake8_forbidden_func-0.1.0.tar.gz
Algorithm Hash digest
SHA256 af382edab9f034e6616d8d94a8cdd3df4a4a0809855badbc7253f3f94527de2d
MD5 a66a5e249a263b7bbc0fce224f98e01b
BLAKE2b-256 16a4f1d79aa5a6c6f37b3af030b48ff882cfa839902416d4a6b5b917c70cf576

See more details on using hashes here.

File details

Details for the file flake8_forbidden_func-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for flake8_forbidden_func-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6b918cef1aef2636fcd4fe629e05c5d5e32543851bed3026abcbd489d9a7f71f
MD5 6d5fe38be90168d20a10a1c875b5a813
BLAKE2b-256 2160d47e5332059af574d40a096861d1f429adc9d0766f916ad483721d492594

See more details on using hashes here.

Supported by

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