Skip to content
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

Closed
wants to merge 3 commits into from

Conversation

vladmos
Copy link
Member

@vladmos vladmos commented Feb 25, 2019

Replaces legacy keyword arguments with positional arguments in some builtin functions, e.g. bool(x = foo) -> bool(foo).

Fixes bazelbuild/bazel#5010

@laurentlb
Copy link
Contributor

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,

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.

Copy link
Member Author

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

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.

Copy link
Member Author

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",

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.

Copy link
Member Author

@vladmos vladmos Feb 25, 2019

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.

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.

@laurentlb
Copy link
Contributor

This change looks limited to 1-arg functions?
What about these cases?

int(2, base = 3)
range(2, 5, step = 2)

@vladmos
Copy link
Member Author

vladmos commented Feb 25, 2019

It's not limited to 1-arg functions, but for now only converts the first argument (see getattr and hasattr in the tests), it just only converts the first argument. As we haven't agreed yet which parameters to make positional only, I've only implemented the most obvious fixes (e.g. a parameter called x never improves readability of the code).

I'll update the PR (or send a separate if this one gets merged) once we finalize the list of parameters to fix.

@vladmos vladmos closed this May 17, 2019
@vladmos vladmos deleted the keyword_arguments branch May 17, 2019 10:30
@laurentlb
Copy link
Contributor

What's the status of this?

@vladmos
Copy link
Member Author

vladmos commented Aug 2, 2019

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?

@laurentlb
Copy link
Contributor

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 base in int(x, base = 2). In Blaze functions, we can make the exclude more explicit:

- glob(["*.cc"], ["test*])
+ glob(["*.cc"], exclude = ["test*])

@vladmos
Copy link
Member Author

vladmos commented Aug 6, 2019

Reopened as #692

@alandonovan
Copy link

For the core Starlark builtins, I think the only one that can be named is base in int(x, base = 2). In Blaze functions, we can make the exclude more explicit:

I think the following built-in functions allow some named arguments: print, sorted, fail, int, min, max.
We should make the docs more explicit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Keyword arguments are being accepted where they should be disallowed
4 participants