pydantic / bump-pydantic

Convert Pydantic from V1 to V2 ♻
MIT License
303 stars 24 forks source link

Rule BP002: Replace Config class by model_config attribute does not keep the arbitrary_types_allowed argument value #137

Closed clemgaut closed 10 months ago

clemgaut commented 10 months ago

I had a pydantic model with a config having arbitrary_types_allowed set to True

class MyModel(BaseModel):
    class Config:
        arbitrary_types_allowed: bool = True

    variable1: np.ndarray
    variable2: float

After applying the bump-pydantic script, it generated the following code:

class MyModel(BaseModel):
    model_config = ConfigDict()

    variable1: np.ndarray
    variable2: float

I would have expected the following code:

class MyModel(BaseModel):
    model_config = ConfigDict(arbitrary_types_allowed=True)

    variable1: np.ndarray
    variable2: float