Replace instance access of model_fields / model_computed_fields

Proprietary

Pydantic 2.11 deprecated accessing model_fields and model_computed_fields on a model instance; these are removed in Pydantic 3.0. Replace <instance>.model_fields with type(<instance>).model_fields (and likewise for model_computed_fields) when the receiver resolves to a Pydantic model instance, so the attribute is accessed on the class. Only fires where the receiver is a variable, attribute or call result whose type resolves. Class access, including through cls or a type[...] value, is left untouched.

org.openrewrite.python.migrate.pydantic.ReplaceModelFieldsInstanceAccess
mod run . --recipe=org.openrewrite.python.migrate.pydantic.ReplaceModelFieldsInstanceAccess

Install it once, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.