Open fmeum opened 1 year ago
Note that the highly related PEP 3102 keyword-only arguments *
syntax is already supported by Rust Starlark - https://github.com/facebookexperimental/starlark-rust/blob/38f480935dcfaf2a26a7c8e56fa2adc053b37b97/starlark/src/syntax/dialect.rs. It would seem to make sense that if Starlark were extended, it was extended with both.
Keyword-only arguments are also supported in Bazel's implementation of Starlark and, from what I can tell, frequently used, especially in the Starlarkification efforts.
Citing @laurentlb from https://bazelbuild.slack.com/archives/CDCEKVCHY/p1678902971702729?thread_ts=1678902446.157669&cid=CDCEKVCHY
This can be discussed, but I don't think the syntax is very readable or intuitive, or well known by users in general. I think we're likely to push back on this unless there's a clear need.
I agree that the syntax isn't well known and perhaps also not intuitive. But I would consider the concept to be both well-known and intuitive. In more detail:
any
or all
, have positional-only arguments. Both from the point of view of consistency as well as mockability in tests, it seems like pure Starlark definitions of these methods should be able to have the same semantics./
./
when mentally parsing a function definition is generally just fine.
I believe that https://peps.python.org/pep-0570, which describes very simple syntax for positional-only arguments, would be very useful to have in Starlark.
It does enable one to write clean and robust helper functions such as
def format_rule_call(kind, /, **attrs)
ordef replace_fields(struct, /, **replacements)
without having to worry about the edge case where a keyword argumentkind
orstruct
is passed.This can currently be worked around to some extent by giving the positional arguments an odd name (e.g.
__kind
), but that's confusing, not guaranteed not to conflict and at odds with style guides.