Python Type Hints – *args and **kwargs (2021)
11–20 of 158 posts
Re: Python Type Hints – *args and **kwargs (2021)
#12Why do people not just type everything they want passed? def variable(n:str, nn:str, nnn:str, *, a:int, b:int, c:int) Anything after,*, is a kwarg.
Your signature requires exactly 3 positional[0] and 3 keyword arguments. The OP allows any number of either. [0] actually 3 positional-or-keyword which is even more widely divergent
Re: Python Type Hints – *args and **kwargs (2021)
#13The ability of **kwargs to leave behind no proper documentation and silently swallow any invalid arguments has made us remove them entirely from our codebase. They're almost entirely redundant when you have dataclasses.
Re: Python Type Hints – *args and **kwargs (2021)
#14This does restrict all of your keyword arguments to the same type. If you have keyword arguments of different types, you're right back to no type safety.
Re: Python Type Hints – *args and **kwargs (2021)
#15Why do people not just type everything they want passed? def variable(n:str, nn:str, nnn:str, *, a:int, b:int, c:int) Anything after,*, is a kwarg.
The wrapper is usually some shorthand for building a handful of those args or adding some side-effect, while still allowing the caller access to the remaining config options via kwargs.
Here's one example of that in the wild https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot....
Re: Python Type Hints – *args and **kwargs (2021)
#16Although these two comes in handly, people have been using them wrong. Often in scientific open source package, they slap *kwargs in function definition without documentation. How am I suppose to know what to pass in? https://qiskit.org/ecosystem/aer/stubs/qiskit_aer.primitives...
Re: Python Type Hints – *args and **kwargs (2021)
#17The ability of **kwargs to leave behind no proper documentation and silently swallow any invalid arguments has made us remove them entirely from our codebase. They're almost entirely redundant when you have dataclasses.
Re: Python Type Hints – *args and **kwargs (2021)
#18https://stackoverflow.com/questions/47060133/python-3-type-h...
what a disaster
Re: Python Type Hints – *args and **kwargs (2021)
#19Although these two comes in handly, people have been using them wrong. Often in scientific open source package, they slap *kwargs in function definition without documentation. How am I suppose to know what to pass in? https://qiskit.org/ecosystem/aer/stubs/qiskit_aer.primitives...
Sadly a problem with any wrapper function is that it nullifies this kind of information. Use functools.wraps.
Maybe in some use case people need to merge 2 functions into 1, I don't know if it can handle this situation.
Re: Python Type Hints – *args and **kwargs (2021)
#20Although these two comes in handly, people have been using them wrong. Often in scientific open source package, they slap *kwargs in function definition without documentation. How am I suppose to know what to pass in? https://qiskit.org/ecosystem/aer/stubs/qiskit_aer.primitives...
I work in a large python codebase, we have almost no usage of `*kwargs` beyond proxy methods because of the nature of how they obfuscate the real interface for other developers.