pydantic / bump-pydantic

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

:sparkles: only add classmethod decorator with validator if it doesn't already exist #120

Open ff137 opened 1 year ago

ff137 commented 1 year ago

I ran bump-pydantic on one of our projects, and it has auto-converted the following, from:

    @root_validator(pre=True)
    @classmethod

to:

    @model_validator(mode="before")
    @classmethod
    @classmethod

This PR amends this behavior to only add the classmethod decorator if it doesn't already exist.

To test, I ran pip install /path/to/my/fork, and ran bump-pydantic . again. Now the extra decorator won't be added unnecessarily

Edit: Also added some tests to validate behavior