4 ms·
Modern Python lets you explicitly opt out of this by putting “/“ in your argument list iirc correctly: def only_positional(a, b, /): Pass Similarl
by wwright 6y ago
Modern Python lets you explicitly opt out of this by putting “/“ in your argument list iirc correctly:
def only_positional(a, b, /):
Pass
Similarly, you can prevent keyword args from being called as positional (which has the inverse problem of breaking client code by changing the order of keyword arguments):
def only_keyword(*, foo, bar):
pass
- dralley 6y agoThe first feature pretty much only exists to make interop with C apis less error prone. It's not really something that should be used in idiomatic Python
- dragonwriter 6y ago> The first feature pretty much only exists to make interop with C apis less error prone. It makes it so that certain built-ins and native APIs can be properly typed, sure, but positional/keyword interchangeability is arguably a violation of the Zen, too.
- wwright 6y agoI disagree for the exact reason the thread here started: it’s part of your public API. If you don’t want keyword arguments in your public API contract, you absolutely should omit them from the contract.