News for hackers. Stuff that matters.
Re:Strict Python function parameters by nyellin on Sunday January 23, 2022 @11:51AM (#30047682)
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://fastapi.tiangolo.com/

https://github.com/tiangolo/typer

We're using Pydantic for 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.

Re:Strict Python function parameters by tempest_ on Sunday January 23, 2022 @12:07PM (#30047849)
We 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.

Re:Strict Python function parameters by BeefySwain on Sunday January 23, 2022 @05:36PM (#30051257)
> 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.

Re:Strict Python function parameters by nyellin on Sunday January 23, 2022 @03:23PM (#30050087)
Interesting, thanks. I hadn't thought of that aspect.
Re:Strict Python function parameters by wheelerof4te on Sunday January 23, 2022 @12:27PM (#30048086)
Not 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.

Re:Strict Python function parameters by macintux on Sunday January 23, 2022 @02:52PM (#30049806)
I’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.
Re:Strict Python function parameters by wheelerof4te on Sunday January 23, 2022 @03:14PM (#30050012)
I 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.

Re:Strict Python function parameters by edgyquant on Sunday January 23, 2022 @03:26PM (#30050110)
You 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.
Re:Strict Python function parameters by peterashford on Sunday January 23, 2022 @03:52PM (#30050337)
100% 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.
Re:Strict Python function parameters by nyellin on Sunday January 23, 2022 @03:22PM (#30050080)
You'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.

Re:Strict Python function parameters by xhevahir on Sunday January 23, 2022 @02:57PM (#30049861)
I'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.
Re:Strict Python function parameters by edgyquant on Sunday January 23, 2022 @03:24PM (#30050094)
Ideally over time more and more libraries will support typing similar to the way the JS/Typescript ecosystem works.
Re:Strict Python function parameters by kuang_eleven on Sunday January 23, 2022 @05:18PM (#30051089)
As 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.

Re:Strict Python function parameters by daanluttik on Tuesday January 25, 2022 @06:17AM (#30070573)
Pydantic 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
Re:Strict Python function parameters by nyellin on Monday January 24, 2022 @02:17AM (#30054496)
Why? What do you dislike about it?