Replies: 2 comments 1 reply
-
|
Thanks @rchen152 for putting this up. Following our email exchange, here are a some notes on what could be supported by static type checkers regarding Pydantic behavior (and challenges in adding such support): Configuration
Change of behavior in V3Pydantic behavior that affect static type checking may change from V2 to V3. The previous configuration is one example, but there could be others (different type coercing mechanisms, features to be removed/added in V3). Pyrefly could read the installed version from the installed package metadata, but I don't know if there are limitations with this approach Type coercionIn non-strict mode, type coercion is performed on most supported types:
|
Beta Was this translation helpful? Give feedback.
-
|
Quick update:
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Starting a discussion about features provided by Pydantic's mypy plugin that we may need to special-case in Pyrefly. As a starting point, here's a list I came up with by diffing the mypy and Pyrefly outputs on Pydantic's mypy plugin tests:
Model configuration
Pydantic supports three ways to configure a model.
model_configattribute [unsupported]Configclass [unsupported]Aliases
Pydantic provides many options for specifying the name by which a field is created versus the name under which it is stored.
alias[already supported]validation_alias: essentially an alias foralias. When both are specified,aliasis ignored. [unsupported]validate_by_name,validate_by_alias: whether fields can be created by name or by alias, respectively [unsupported]alias_generator: a way to programmatically create aliases [unsupported]Extra data
Pydantic lets you configure how extra data is handled. Importantly, the default is to ignore it, not error.
Strict mode
By default, Pydantic coerces data to the desired type, unless its “strict” mode is requested.
Unvalidated model construction
Pydantic provides a
model_constructmethod that bypasses runtime validation. The mypy plugin still performs type validation.Misc.
Lastly, Pyrefly is missing a grab bag of smaller (in terms of expected implementation size) features:
frozencan be set on individual fields.field_validatordecorator transforms decorated instance methods into class methods. Themodel_validatordecorator does this transformation in “before” and “wrap” modes.Beta Was this translation helpful? Give feedback.
All reactions