News for hackers. Stuff that matters.
Re:Strict Python function parameters by wheelerof4te on Sunday January 23, 2022 @12:46PM (#30048342)
"I hate having to have a block of `if bar is None` at the top of my functions."

Why? This is like someone saying "I don't like declaring my variables in C at the top of the function".

It is a good and readable solution to a somewhat rare problem. Passing mutable objects as default function parameters is a common code smell in Python.

And no, adding a special syntax to an already syntax-heavy language to address this is not good.

Re:Strict Python function parameters by softwaredoug on Sunday January 23, 2022 @01:24PM (#30048764)
Because it’s harder for the user of the API to know what the default is.

It’s boilerplate that distracts from the purpose of the function, this getting in the way of readability.

It’s also just more code prone to a programmer screwing up from time to time, despite how simple it is.

Re:Strict Python function parameters by wheelerof4te on Sunday January 23, 2022 @01:48PM (#30049046)
Pythonic way to solve this problem would be to make Bar() a component of another class.

Functions are not a good tool for storing stateful objects in Python. That's why classes exist.