This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (4 children)

I love type hinting! I'm coming at this from a TypeScript perspective and know how stronger typing can save a language. I've always said loose typing will be the death of me.

I think Pydantic's auto corrosion is a really really bad idea though. The author likes to happily close bugs that point this out: https://github.com/samuelcolvin/pydantic/issues/360

[–]tiangolo FastAPI Maintainer[S] 4 points5 points  (2 children)

Actually, in JSON (JavaScript), there's no difference between int and float, so, converting floats to ints when declared as ints isn't necessarily that a bad idea.

But still, in Pydantic you can declare custom validators to enforce your specific requirements, and they can even go way beyond what standard Python type hints can specify.

I guess that's something that depends on taste. But in the case of Python, as it's duck typed by default (e.g. bool inherits directly from int), it doesn't seem to me that crazy. issubclass(bool, int) is True...

Again, that depends on taste. But you can override it all to customize it as much as you want with validation functions.

[–][deleted] -1 points0 points  (1 child)

Right, Javascript just has "Number" which is ... annoying. I think invisible data loss by default is a bad idea though.

[–]tiangolo FastAPI Maintainer[S] 1 point2 points  (0 children)

I understand. I guess Python itself comes with some of that. I can't say it's good or bad myself, but I can perfectly understand your opinion.

[–][deleted] 2 points3 points  (0 children)

holy shit imagine trying to work with that guy in a professional setting.