5 ms·
Slightly off-topic, but everyone writing modern Python should be familiar with Pydantic and similar libraries that use type hints for validation and parsing: h
by nyellin 5y ago
Slightly off-topic, but everyone writing modern Python should be familiar with Pydantic and similar libraries that use type hints for validation and parsing:
https://pydantic-docs.helpmanual.io/ https://pydantic-docs.helpmanual.io/
https://fastapi.tiangolo.com/ https://fastapi.tiangolo.com/
https://github.com/tiangolo/typer https://github.com/tiangolo/typer
We're using Pydantic for Robusta (https://github.com/robusta-dev/robusta https://github.com/robusta-dev/robusta) and absolutely love it. You get the best of traditional Python (rapid prototyping and no boilerplate) while still being able to scale your codebase and keep it maintainable. Robusta is the first large project I've written in Python where I'm not encountering type errors at runtime left and right.
- tempest_ 5y agoWe are using FastAPI a bit and it has been a decent experience. One thing to note about it is tiangolo is pretty content to maintain singular control over his projects which means the project only really advances when he has the time or interest to work on that specific project.
- nyellin 5y agoInteresting, thanks. I hadn't thought of that aspect.
- BeefySwain 5y ago> One thing to note about it is tiangolo is pretty content to maintain singular control over his projects which means the project only really advances when he has the time or interest to work on that specific project. Yes, he recently responded to some criticism of this basically saying that he has no real intention to increase the bus factor or permit more community control to his projects, which is obviously his right, but is also something that people should consider when deciding whether or not to go with them.
- wheelerof4te 5y agoNot everyone is using Pydantic (nor do I see the reason to) or even type hints, for that matter. Type hints are great when combined with a good IDE such as Pycharm, but are otherwise useless for Python. Sometimes, they are even missleading. Often they don't cover all the call options. Complicated function calls should be made with keywords anyway. Leave positional only parameters to obvious functions such as pow() or sqrt(). The speed hit should be minimal. You are using Python, where dot access is a much more bigger performance eater than keyword arg functions.
- macintux 5y agoI’ve certainly avoided a nasty bug or two with Python type hints without an IDE. Not sure why you’re so hostile to the idea, the OP didn’t say everyone must use them, just that it’s helpful to be familiar with them.
- wheelerof4te 5y agoI am seemingly hostile to the idea because it is turning Python into somethimg it never should have been. Python does not have the scale to make typing worthwhile, but people are already making it a required Python skill. I this feature is optional, then I should not be required to know it, right? If you want static typing, please use another language that makes use of them to actually speed up the code. Let's keep the docstrings for documentation.
- edgyquant 5y agoYou aren’t required to know it but I don’t think it’s fair for you to say that typing shouldn’t be added just because you don’t want to use it. JavaScript had been made better in the form of typescript and I’d love to use a truly typed python as well.
- peterashford 5y ago100% this. I like Python but I'm working on a large inherited code base and type hints on parameters would have made this much easier. Stronger typing would be a good thing imo.
- nyellin 5y agoYou're right about the performance. When I mentioned scaling I had in mind other issues with a large codebase - not actual performance at runtime. For example, before type hints I found it difficult (even with PyCharm and other IDEs) to safely refactor code. I would end up missing specific usages of an old member name and discover it at runtime when the code raised an exception. In the best case scenario I would find it when running tests. In the worst case, in production. Type hints make this a moot point, at least in real world usage. With type hints the IDE is smart enough to find all references when refactoring.
- xhevahir 5y agoI've never understood what I'm supposed to do with things like this or mypy when--as is usually the case--I'm making heavy use of other libraries that don't have type annotations. The examples and tutorials I've seen always show the code importing standard-library modules and nothing else.
- edgyquant 5y agoIdeally over time more and more libraries will support typing similar to the way the JS/Typescript ecosystem works.
- kuang_eleven 5y agoAs a counterpoint, I cannot stand Pydantic. Type hinting in function class parameters is super useful, but kludges like Pydantic that abuse Python to turn those into runtime checks? Never again. I am currently finishing up a moderately sized project in FastAPI, and for my next project I will strongly be recommending using Starlette alone.
- nyellin 5y agoWhy? What do you dislike about it?
- daanluttik 5y agoPydantic is great for parsing input either from api's or user input. You often want these runtime checks. But I would argue that the benefits lowers when you are not talking about cross-system interfaces