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 |
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
Built Distribution
File details
Details for the file flake8_forbidden_func-0.0.2.tar.gz
.
File metadata
- Download URL: flake8_forbidden_func-0.0.2.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c96729f4ff50ffcabf7850b722e63c51b8631ad575505427ff99bc51c874571 |
|
MD5 | e6c8e266549c4ee604de3ef095e7296b |
|
BLAKE2b-256 | 4662383a266c45f28440132d5c3de5ba7f4cac330964332b915f17e30e40e3e9 |
File details
Details for the file flake8_forbidden_func-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: flake8_forbidden_func-0.0.2-py3-none-any.whl
- Upload date:
- Size: 10.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa0ed4e06f4216b31e21ffb4f7c78d62ba92589fd7eaedccfeeeb6983abff5b3 |
|
MD5 | d38ed46d2a4316775458e47236152e20 |
|
BLAKE2b-256 | 60122c7abba7ac7a649310eec7c7c6f0a33f2033e0bbde23fec04567a2e70205 |