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 theforwards_tochain (including chained forwarders) to the targetModelableand 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
Release history Release notifications | RSS feed
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e41246216a3933f657984aaaa7180c8c545467c97d8568f94a21bc714cdb4c9c
|
|
| MD5 |
a6a724992d9e9ff64ff1e1b0134eb36d
|
|
| BLAKE2b-256 |
1dc4c4fb99da2861de12453ad49536a9807cab31a7411f1d7f0a5c6b810241e8
|
Provenance
The following attestation bundles were made for pydantic_modelable_mypy-0.4.0.tar.gz:
Publisher:
workflow.yml on Joacchim/pydantic-modelable
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pydantic_modelable_mypy-0.4.0.tar.gz -
Subject digest:
e41246216a3933f657984aaaa7180c8c545467c97d8568f94a21bc714cdb4c9c - Sigstore transparency entry: 2132462705
- Sigstore integration time:
-
Permalink:
Joacchim/pydantic-modelable@3f5cc8cdfca05a5086c59ce848d358615a003804 -
Branch / Tag:
refs/tags/0.4.0 - Owner: https://github.com/Joacchim
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@3f5cc8cdfca05a5086c59ce848d358615a003804 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pydantic_modelable_mypy-0.4.0-py3-none-any.whl.
File metadata
- Download URL: pydantic_modelable_mypy-0.4.0-py3-none-any.whl
- Upload date:
- Size: 11.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d69fd28dfc32faeba8974ca5e723f111ed926030f296d02510a201ac5cef0e1c
|
|
| MD5 |
4e58f5adc47361173eb75f25cc76b66c
|
|
| BLAKE2b-256 |
4be79462a56aa4e27d31c6e620ce7781356da0b027997af319d22b95dbd980b5
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pydantic_modelable_mypy-0.4.0-py3-none-any.whl -
Subject digest:
d69fd28dfc32faeba8974ca5e723f111ed926030f296d02510a201ac5cef0e1c - Sigstore transparency entry: 2132462861
- Sigstore integration time:
-
Permalink:
Joacchim/pydantic-modelable@3f5cc8cdfca05a5086c59ce848d358615a003804 -
Branch / Tag:
refs/tags/0.4.0 - Owner: https://github.com/Joacchim
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@3f5cc8cdfca05a5086c59ce848d358615a003804 -
Trigger Event:
push
-
Statement type: