With names this short? No, I’m not going to argue that it’s more clear. And that’s the problem with toy examples. But what if it’s longer? The standard library contains 525 cases where the x=x
notation is used with a parameter name of 10 characters or more. Just in case unit testing produces unfair results, I excluded Lib/test - still found 310 examples with >=10 character parameter names. And I would absolutely argue that there’s clarity to be gained here:
ElementTree(element).write(stream, encoding,
xml_declaration=xml_declaration,
default_namespace=default_namespace,
method=method,
short_empty_elements=short_empty_elements)
# vs #
ElementTree(element).write(stream, encoding,
xml_declaration=,
default_namespace=,
method=,
short_empty_elements=)
Notably, also, I would then change encoding
to be a kwarg, as there’s now almost no cost to doing so.
Python, as a general rule, avoids massive amounts of boilerplate. When you write code in some languages, AI code generators can contribute extensively by filling in the boring and obvious details after you’ve typed in a little bit of something. (I’ve seen this in action many times.) Python tends to not have that repetition in the first place, which makes the AI tools look less impressive, but it means programmers have less bugs to deal with. So why are we repeating name=name
in so many places here, and do we actually gain anything by it?
These are questions that we can’t answer. Ultimately, once a feature is available, everyone has to make that choice, and no matter how non-controversial a feature is, there’ll always be someone who says “not in MY codebase you won’t”. Which is why we have a choice of which linters to use and how to configure them.
Agreed - brevity alone is not a goal. However, deduplication gives more than brevity - it prevents desynchronization. When xml_declaration=
is the norm, it’s obvious that xml_declaration=html_declaration
must be intentional and cannot possibly be a transcription error (okay, that particular example probably wouldn’t happen, but you get the idea). By eliminating the x=x
possibility, we give people an easy way to recognize bugs.