// rule category
Typing, async, and env hygiene in Python/Django/FastAPI.
70 rules · 7 critical · 24 high · 39 low
Identify function definitions where a mutable object (e.g., list, dictionary, set) is used as a default argument. This can cause shared state across function calls, leading to unintended behavior. Suggest using `None` as a default and initializing the object inside the function.
Verify that after loading a PyTorch model, either `model.eval()` or `model.train()` is called. Failing to do so can result in incorrect behavior, especially for layers like dropout and batch normalization.
Ensure that resources such as files, sockets, or database connections are managed using the `with` statement. Code that explicitly calls `.close()` without `with` should be refactored to use context managers for automatic resource cleanup.
Detect relative imports (e.g., `from .module import x`). Relative imports can break if the project structure changes. Recommend using absolute imports (`from package.module import x`) for better clarity and maintainability.
Check if the code imports individual classes or functions instead of the entire module. Directly importing specific classes or functions can clutter the titlespace and increase naming conflicts. Recommend importing the module and referencing items explicitly.