Flake8 plugin for detecting static-analysis escape hatches in Python code
Project description
flake8-agents
flake8-agents is a Flake8 plugin for codebases that use AI-generated Python.
It exists because generated code often hides problems from static analysis with
reflection, broad types, casts, raw namespace access, and stale suppressions.
The plugin turns those escape hatches into explicit AGT diagnostics.
Usage
uv sync
uv run flake8 --select AGT src
uv run module-size src --warn-lines 800 --error-lines 1000
Minimal Flake8 config:
[flake8]
select = AGT
Rules
Suppressions
| Code | Catches | Example |
|---|---|---|
AGT001 |
unused explicit AGT noqa suppressions |
value: int = 1 # noqa: AGT105 |
AGT100 |
broad type-checker suppressions | value = 1 # type: ignore[assignment] |
Type escapes
| Code | Catches | Example |
|---|---|---|
AGT101 |
typing.cast used as a narrowing bypass |
result = cast(int, value) |
AGT102 |
broad object annotations |
def handle(value: object) -> None: ... |
AGT103 |
known-shape containers that erase value shape | payload: dict[str, object] |
AGT104 |
vague callable signatures | callback: Callable[..., int] |
AGT105 |
broad Any at non-local boundaries |
def handle(value: Any) -> None: ... |
AGT106 |
legacy type-parameter factories | T = TypeVar("T") |
AGT107 |
classmethod factories returning their class name | def build(cls) -> "Box": ... |
Dynamic anti-patterns
| Code | Catches | Example |
|---|---|---|
AGT200 |
dynamic attribute reads | value = getattr(target, "name") |
AGT201 |
dynamic attribute writes | setattr(target, "name", value) |
AGT202 |
raw namespace extraction | namespace = vars(target) |
AGT203 |
dynamic import builtin | module = __import__("package") |
AGT204 |
importlib.import_module calls |
module = importlib.import_module("package") |
AGT205 |
setattr-style mutation methods | target.setattr("name", value) |
AGT206 |
direct __setattr__ calls |
target.__setattr__("name", value) |
AGT207 |
direct __new__ construction |
instance = Target.__new__(Target) |
AGT208 |
direct raw __dict__ indexing |
value = target.__dict__["name"] |
AGT209 |
aliasing raw __dict__ |
namespace = target.__dict__ |
AGT210 |
indexing raw __dict__ aliases |
value = namespace["name"] |
AGT211 |
aliasing dotted module imports | import package.module as alias |
Import boundaries
| Code | Catches | Example |
|---|---|---|
AGT300 |
private project imports across module boundaries | from module import _private |
AGT301 |
configured retired project import paths | import module.legacy |
AGT302 |
declarations before the module import section is complete | VALUE = 1 before import ast |
module-size
module-size is a separate command that fails on oversized Python modules.
uv run module-size src --warn-lines 800 --error-lines 1000
| Option | Default | Meaning |
|---|---|---|
paths |
required | Python files or directories to scan |
--warn-lines |
800 |
print warning findings at or above this line count |
--error-lines |
1000 |
return failure at or above this line count |
--exclude REGEX |
none | skip files whose resolved path matches the regex |
--suppress-warnings |
false |
hide warning findings from stdout |
PATH LINES LEVEL THRESHOLD
/path/to/src/package/large.py 1012 error 1000
Python support
flake8-agents supports Python >=3.10 and is typed (py.typed). Runtime
dependencies are intentionally small: flake8 and typing-extensions.
License
MIT. See LICENSE.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flake8_agents-0.1.2.tar.gz.
File metadata
- Download URL: flake8_agents-0.1.2.tar.gz
- Upload date:
- Size: 107.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fd73fc4aa71509d8698b388aab0fbd07375210f8240fbaee0961794e95021b26
|
|
| MD5 |
3236c390a694dfb97b959e46e2f5b94a
|
|
| BLAKE2b-256 |
dfe4bc40c57c57a89380a656c39a9f6803e1e886ffae5bc5136344d2add248e1
|
File details
Details for the file flake8_agents-0.1.2-py3-none-any.whl.
File metadata
- Download URL: flake8_agents-0.1.2-py3-none-any.whl
- Upload date:
- Size: 22.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
61a199a60a4abdd72a091ad5051964997dd0d867e169293681df8de052d10978
|
|
| MD5 |
26c856bae588983d8aa80b2af4509aa8
|
|
| BLAKE2b-256 |
3e0131e5e6c022cbc3e1cfebe4f3c88897184e717e271965a8a159bd3bf6d538
|