Skip to main content

A mypy plugin teaching the type-checker about pydantic-modelable runtime model extensions

Project description

pydantic-modelable-mypy

A mypy plugin that teaches the type-checker about the model extensions pydantic_modelable performs at runtime.

Why

pydantic_modelable lets a class decorate a different, pre-existing model to add fields, union members or enum values to it. A decorator cannot re-type a third class in the standard type system, so mypy --strict reports the added fields as unknown attributes. This plugin observes those decorators and injects the corresponding members into the target model during analysis.

Usage

Install alongside pydantic-modelable and enable the plugin in your mypy configuration:

[mypy]
plugins = pydantic_modelable_mypy.plugin

What it covers

  • as_attribute — the injected field is known for reads and construction.
  • extends_union — the field is typed as the discriminated union of the base's subtypes (reads and construction), including subtypes defined in other modules, on full and incremental runs.
  • extends_enum — the discriminator values injected as enum members are resolved by name (Palette.red).
  • ModelableForwarder — decorators applied through a forwarder (@Fwd.as_attribute(...)) are resolved through the forwards_to chain (including chained forwarders) to the target Modelable and handled as above.

Limitation (extends_enum member names)

Enum member access on an unknown name offers no plugin hook, so injected member names can only be resolved from subtypes discovered during analysis. This is reliable on full (non-incremental) runs (e.g. CI with mypy fresh, or --no-incremental). On incremental / daemon runs, subtypes served from cache are not re-analysed, so member-name access (Palette.red) may report an unknown attribute until a clean run. Everything else ModelableStrEnum provides — iteration, membership, construction, .value — works in all modes, as does all of as_attribute and extends_union.

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

pydantic_modelable_mypy-0.4.0.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pydantic_modelable_mypy-0.4.0-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file pydantic_modelable_mypy-0.4.0.tar.gz.

File metadata

  • Download URL: pydantic_modelable_mypy-0.4.0.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pydantic_modelable_mypy-0.4.0.tar.gz
Algorithm Hash digest
SHA256 e41246216a3933f657984aaaa7180c8c545467c97d8568f94a21bc714cdb4c9c
MD5 a6a724992d9e9ff64ff1e1b0134eb36d
BLAKE2b-256 1dc4c4fb99da2861de12453ad49536a9807cab31a7411f1d7f0a5c6b810241e8

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydantic_modelable_mypy-0.4.0.tar.gz:

Publisher: workflow.yml on Joacchim/pydantic-modelable

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pydantic_modelable_mypy-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pydantic_modelable_mypy-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d69fd28dfc32faeba8974ca5e723f111ed926030f296d02510a201ac5cef0e1c
MD5 4e58f5adc47361173eb75f25cc76b66c
BLAKE2b-256 4be79462a56aa4e27d31c6e620ce7781356da0b027997af319d22b95dbd980b5

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydantic_modelable_mypy-0.4.0-py3-none-any.whl:

Publisher: workflow.yml on Joacchim/pydantic-modelable

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page