Skip to main content

PydanticPlugin

The Pydantic mypy plugin.

Attributes

AttributeTypeDescription
plugin_config[PydanticPluginConfig](../v1/mypy/pydanticpluginconfig.md?sid=pydantic_v1_mypy_pydanticpluginconfig)Configuration object containing Pydantic-specific settings parsed from mypy options.
_plugin_datadict[str, Any]A dictionary representation of the plugin configuration used by mypy to determine if the cache needs to be discarded.

Constructor

Signature

def PydanticPlugin(
options: Options
) - > None

Parameters

NameTypeDescription
optionsOptionsThe mypy options used to configure the plugin.

Methods


get_base_class_hook()

@classmethod
def get_base_class_hook(
fullname: str
) - > Callable[[ClassDefContext], None]| None

Update Pydantic model class.

Parameters

NameTypeDescription
fullnamestrThe fully qualified name of the base class being processed by mypy

Returns

TypeDescription
`Callable[[ClassDefContext], None]None`

get_metaclass_hook()

@classmethod
def get_metaclass_hook(
fullname: str
) - > Callable[[ClassDefContext], None]| None

Update Pydantic ModelMetaclass definition.

Parameters

NameTypeDescription
fullnamestrThe fully qualified name of the metaclass being checked

Returns

TypeDescription
`Callable[[ClassDefContext], None]None`

get_method_hook()

@classmethod
def get_method_hook(
fullname: str
) - > Callable[[MethodContext], Type]| None

Adjust return type of from_orm method call.

Parameters

NameTypeDescription
fullnamestrThe fully qualified name of the method being called

Returns

TypeDescription
`Callable[[MethodContext], Type]None`

get_dynamic_class_hook()

@classmethod
def get_dynamic_class_hook(
fullname: str
) - > Callable[[DynamicClassDefContext], None]| None

Recognize create_model() calls as dynamic BaseModel subclasses.

Parameters

NameTypeDescription
fullnamestrThe fully qualified name of the function creating a dynamic class

Returns

TypeDescription
`Callable[[DynamicClassDefContext], None]None`

report_config_data()

@classmethod
def report_config_data(
ctx: ReportConfigContext
) - > dict[str, Any]

Return all plugin config data. Used by mypy to determine if cache needs to be discarded.

Parameters

NameTypeDescription
ctxReportConfigContextThe context provided by mypy for reporting configuration data

Returns

TypeDescription
dict[str, Any]A dictionary containing the current plugin configuration state for cache validation