Pylint Pydantic Plugin
Pylint-pydantic is a Pylint plugin designed to enhance Pylint's understanding of Pydantic models, reducing false positives and improving static analysis for Pydantic-heavy codebases. The current version is 0.4.1, and it maintains an active release cadence, frequently updating to support new major versions of Pylint and Pydantic, as well as addressing bug fixes.
Warnings
- breaking Pylint-pydantic v0.4.0 dropped support for Python 3.9. Users on Python 3.9 must use an older version of the plugin or upgrade their Python interpreter.
- breaking Compatibility with Pylint major versions has changed. Pylint-pydantic v0.3.0 introduced support for Pylint 3, and v0.4.0 introduced support for Pylint 4. Ensure your `pylint-pydantic` version matches your `pylint` major version.
- gotcha When using Pydantic V2, ensure you are using `pylint-pydantic` v0.2.0 or newer. Older versions may not correctly interpret Pydantic V2 features, leading to false positives or missed warnings.
- gotcha Pylint may emit `no-name-in-module` or `no-member` warnings for Pydantic `BaseModel` attributes if the plugin is not correctly loaded or if an older Pylint version is used without proper configuration.
Install
-
pip install pylint-pydantic
Imports
- pylint_pydantic
pylint --load-plugins pylint_pydantic your_module.py
Quickstart
from pydantic import BaseModel, Field
class User(BaseModel):
name: str = Field(min_length=1)
age: int
# Save this as 'my_models.py'
# Then run pylint from your terminal:
# pylint --load-plugins pylint_pydantic my_models.py