-
Notifications
You must be signed in to change notification settings - Fork 426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix for legacy named arguments #559
Conversation
cc @alandonovan, fyi |
WARNINGS.md
Outdated
* Category_name: `keyword-parameters` | ||
* Automatic fix: yes | ||
|
||
Some parameters for builtin functions in Skyalrk are keyword for legacy reasons, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: Skylark.
but really: Starlark.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, fixed.
WARNINGS.md
Outdated
* Automatic fix: yes | ||
|
||
Some parameters for builtin functions in Skyalrk are keyword for legacy reasons, | ||
their names are not meaningful (e.g. `x`), making them positional will improve |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The two commas in this sentence are ungrammatical.
Replace the first with ";" or "and", and the second with a period and capital.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
"type": "x", | ||
"hasattr": "x", | ||
"getattr": "x", | ||
"select": "x", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most often I see string.split(maxsplit=-1) or dict.get(key, default=...). Be sure to handle methods too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've collected the potential cases here: bazelbuild/bazel#5010 (comment)
I'll implement more fixes once we agree on which keyword parameters we want to deprecate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To repeat what I said on that issue, the important distinction is between core Starlark (e.g. getattr, splitlines) and the build language (e.g. fail, aspect). In the core, following Python, very few functions accept named arguments; int(base=...) is one of the rare exceptions. In the build language, and for user-defined macros, it's much more common for functions to accept or even require named arguments. Let me know if you disagree.
This change looks limited to 1-arg functions? int(2, base = 3)
range(2, 5, step = 2) |
It's not limited to 1-arg functions, but for now only converts the first argument (see I'll update the PR (or send a separate if this one gets merged) once we finalize the list of parameters to fix. |
What's the status of this? |
I think I deleted the branch by mistake and Github closed the pull request. But it shouldn't be hard to restore. Is there a decision which arguments we're going to make positional-only? |
Once we have a way to say: "This argument is always positional" or "This argument is always named", we can extend the list of functions to fix. For the core Starlark builtins, I think the only one that can be named is - glob(["*.cc"], ["test*])
+ glob(["*.cc"], exclude = ["test*]) |
Reopened as #692 |
I think the following built-in functions allow some named arguments: print, sorted, fail, int, min, max. |
Replaces legacy keyword arguments with positional arguments in some builtin functions, e.g.
bool(x = foo)
->bool(foo)
.Fixes bazelbuild/bazel#5010