79206710

Date: 2024-11-20 10:11:57
Score: 0.5
Natty:
Report link

If you're always inserting a string there, it might be better to use a computed_field. Something along this, maybe?

class MyModel(BaseModel):
    input: str

    @computed_field
    def x(self) -> int:
        return len(self.input)

I think it's very counterintuitive if you see the model with the int declaration while it would raise type errors if you put an integer inside a JSON at that place.

Reasons:
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (0.5):
Posted by: lord_haffi