2 ms·
Seems reasonable but when are you actually calling foo like: foo(items, num=12, kind=“apple”) vs: foo(items, num=num, kind=kind) ? Then you might as well g
by peteradio 5y ago
Seems reasonable but when are you actually calling foo like:
foo(items, num=12, kind=“apple”)
vs:
foo(items, num=num, kind=kind)
?
Then you might as well get your info from the variable names in the calling method.
- messe 5y agoThere's been some discussion on that[1], with some suggesting the introduction of syntax analogous to f-strings: foo(items, num=, kind=) # equivalent to foo(items, num=num, kind=kind) But as far as I know there hasn't been a formal proposal (I could be wrong, and am happy to be corrected on this). [1]: https://lwn.net/Articles/818129/ https://lwn.net/Articles/818129/
- hprotagonist 5y agothat looks nice! not essential, but nice. I like the similar 3.8+ f-string improvement: x=5 print(f”{x=}”)
- hprotagonist 5y agoand one day someone goofs and foo(items, kind, num) and then everyone is sad again.
- wheelerof4te 5y agoYes, but keyword arguments are a good fallback option. They indicate that you are indeed passing the required arguments. So, the def foo(val, querry=querry): ... doesn't look as funny as you might think.