PEP 736: Keyword Argument Shorthand: Final Draft

When considering language changes like this, I find it useful to play with the functionality in an editor. To facilitate such exploration and feedback from the community, I’ve implemented provisional support for draft PEP 736 in the latest version of pyright. If you’re not familiar with pyright, it’s both a static type checker (like mypy) and a language server (like jedi).

If you want to play with the proposed PEP 736 syntax, you can install the latest version of pyright (1.1.373) in your own editor or use the web-based pyright playground. You’ll need to tell pyright that it should assume Python version 3.14.

Here are a few of my own observations about the PEP 736 changes…

With today’s method of specifying keyword arguments (e.g. param1=param1), the left identifier unambiguously refers to the target parameter in the callee and the right identifier refers to a local symbol. These can have different static types, and hovering over them in a smart editor reveals these differences.

image image

Once these two identifiers are “fused” into one, it’s not as clear what should be displayed when hovering. In my implementation, I chose (somewhat arbitrarily) to display information about the local symbol.

image

Similarly, when renaming the identifier, it’s not immediately obvious whether the intent of the user is to rename the target parameter in the callee or the local symbol.

image image

A similar issue will exist for semantic highlighting, where tokens are colored according to their semantic meaning. It’s not clear what semantic meaning should be ascribed to the “fused” identifier.

So while the new syntax is less verbose (which can aid in readability), it adds a little ambiguity. I personally don’t find this to be a big problem.

Overall, I’m +0 on the proposal in the PEP, but I’m interested to hear what others think once they’ve had a chance to play with the feature.

If the PEP authors are looking for additional “prior art” examples, Javascript and TypeScript support a similar shortcut for object literals: { field1: 0, field2: null, field3 }. This tends to be used extensively in modern Javascript code.

14 Likes