You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TRY003 and TRY004 are currently being flagged inside field_validator method of the Pydantic library.
TRY003 can easily be fixed by creating a new Exception that inherits ValueError, but honestly just seems way too overkill.
TRY002 is not as fixable tho since Pydantic forces the user to raise a ValueError, and raising a TypeError won't integrate well with the library.
E.g.
frompydanticimportBaseModel, field_validatorfrompydantic_core.core_schemaimportValidationInfoclassPersonWithBigName(BaseModel):
name: strsurname: strage: int@field_validator("name")def_name_must_be_big(cls, value: str, , info: ValidationInfo) ->striflen(value) <10:
raiseValueError(f"{info.field_name} must be bigger!") # TRY003 returnvalue@field_validator("age")def_convert_str_to_int(cls, value: str, info: ValidationInfo) ->strifnotisinstance(value, str):
raiseValueError(f"{info.field_name} must be a string!") # TRY003 and TRY004returnint(value)
Maybe some sort of allow list for TRY003 would be a nice idea, as for TRY004 I believe a way of understanding if it's a Pydantic validator or not would be ideal.
I am willing to help in any way I can, thanks for your time :)
The text was updated successfully, but these errors were encountered:
TheForgottened
changed the title
TRY003 and TRY004 being triggered inside Pyndatic's field_validator
TRY003 and TRY004 being triggered inside Pydantic's field_validator
Nov 15, 2023
TRY003 and TRY004 are currently being flagged inside field_validator method of the Pydantic library.
TRY003 can easily be fixed by creating a new Exception that inherits ValueError, but honestly just seems way too overkill.
TRY002 is not as fixable tho since Pydantic forces the user to raise a ValueError, and raising a TypeError won't integrate well with the library.
E.g.
Maybe some sort of allow list for TRY003 would be a nice idea, as for TRY004 I believe a way of understanding if it's a Pydantic validator or not would be ideal.
I am willing to help in any way I can, thanks for your time :)
The text was updated successfully, but these errors were encountered: