-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Keyword arguments are being accepted where they should be disallowed #5010
Comments
To be clear, only some builtin functions are affected. It looks like in the vast majority of cases, the functions that have been migrated are functions that take almost all their parameters by keyword anyway, so there shouldn't be much difference noticed. |
Reassigning to Chris since he's managing Build Api related issues. |
This is on my radar for this quarter. |
Note that converted parameter @param annotations need legacyNamed = true (and in some places, noneable = True) to retain compatibility with the bugginess of SkylarkSignature. This facilitates followup to clean up these methods / parameters -- given the refactor, we can enforce some of these parameters are positional-only (subject to an --incompatible flag) Progress toward #5010 RELNOTES: None. PiperOrigin-RevId: 230975480
*** Reason for rollback *** Breaks lots of tests with "method 'getattr' returns an object of invalid type SingletonSet" error; see b/123520324 *** Original change description *** Convert MethodLibrary's SkylarkSignature methods to SkylarkCallable Note that converted parameter @param annotations need legacyNamed = true (and in some places, noneable = True) to retain compatibility with the bugginess of SkylarkSignature. This facilitates followup to clean up these methods / parameters -- given the refactor, we can enforce some of these parameters are positional-only (subject to an --incompatible flag) Progress toward #5010 RELNOTES: None. PiperOrigin-RevId: 231264758
Note that converted parameter @param annotations need legacyNamed = true (and in some places, noneable = True) to retain compatibility with the bugginess of SkylarkSignature. This facilitates followup to clean up these methods / parameters -- given the refactor, we can enforce some of these parameters are positional-only (subject to an --incompatible flag) Progress toward bazelbuild#5010 RELNOTES: None. PiperOrigin-RevId: 230975480
*** Reason for rollback *** Breaks lots of tests with "method 'getattr' returns an object of invalid type SingletonSet" error; see b/123520324 *** Original change description *** Convert MethodLibrary's SkylarkSignature methods to SkylarkCallable Note that converted parameter @param annotations need legacyNamed = true (and in some places, noneable = True) to retain compatibility with the bugginess of SkylarkSignature. This facilitates followup to clean up these methods / parameters -- given the refactor, we can enforce some of these parameters are positional-only (subject to an --incompatible flag) Progress toward bazelbuild#5010 RELNOTES: None. PiperOrigin-RevId: 231264758
cc @vladmos |
That looks like an easy cleanup for buildifier. Is there a complete list of functions with keywords that shouldn't be accepted? |
Any Example:
|
The bazel/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/SkylarkRuleFunctionsApi.java Line 97 in c33ae8a
|
It looks like |
Summarizing our offline discussion: In cases where we make the call to make the param unspecifiable by name, this is technically a breaking change, so we need to attach it to an incompatible flag. We don't have the infrastructure to do this yet, so I'll need to implement this infrastructure. |
There are the following usage of
String methods:
Some builtins with keyword parameters that we'd probably like to make positional-only are
I can make a buildifier fix for some of the parameters above and update it later as we agree on making more parameters positional. I guess all parameters called |
We should (if it hasn't already been done) manually vet changes we make to arguments' keywordy-ness against the behavior of Python 2 and 3 to confirm we're making things more consistent. But even if a change is inconsistent, we can still go ahead with it if it helps readability. |
Created a prototype: bazelbuild/buildtools#559 Once we agree on the list of functions and their arguments (it doesn't have to be the final list, can be extended any time), I'll merge it to buildifier. |
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. There is something ironic about the fact that the core is moving closer to Python (removing names) while the build language is moving towards Python3 by allowing users to require names in their functions. But I think it is the right thing. |
This change creates --experimental_restrict_named_params to make all builtin Starlark parameters which are named via legacyNamed = true to instead be treated as positional-only. This is a step on the path to cleaning up namedness of builtin Starlark parameters. When we finalize the list of parameters which should truly be positional-only, we can change this flag to be prefixed with --incompatible instead of --experimental, as per the incompatible change policies. Progress toward #5010. RELNOTES: None. PiperOrigin-RevId: 236898018
…larkCallable Original description: Note that converted parameter @param annotations need legacyNamed = true (and in some places, noneable = True) to retain compatibility with the bugginess of SkylarkSignature. This facilitates followup to clean up these methods / parameters -- given the refactor, we can enforce some of these parameters are positional-only (subject to an --incompatible flag) Progress toward #5010 RELNOTES: None. PiperOrigin-RevId: 243891931
These were historically marked legacyNamed because the ability to refer to these parameters by keyword was not historically explicitly declared -- these were thus marked as "keyword-specifiable because of legacy infrastructure limitations". However, these particular usages are specified by keyword almost universally. We should therefore make explicit that specifying these parameters by keyword is intended behavior. Progress toward #5010 RELNOTES: None. PiperOrigin-RevId: 244210997
…d-specifiable Progress toward #5010. RELNOTES: None. PiperOrigin-RevId: 244211187
These parameters were marked as "keyword-specifiable because of legacy infrastructure limitations". Some such parameters are specified by keyword almost universally: these parameters are migrated to "keyword-specifiable by intention". Others are kept under "legacyNamed" to be deprecated with --experimental_restrict_named_params Progress toward #5010 RELNOTES: None. PiperOrigin-RevId: 244216657
…ation Progress toward #5010 RELNOTES: None. PiperOrigin-RevId: 245320507
Marking fixed, as #8147 is fixed. |
Some builtin functions accept keyword arguments where they should be positional-only. This creates unnecessary differences from Python and perhaps promotes bad style.
Example:
This comes from a bug in how
Param#named
is ignored for@SkylarkSignature
. As we migrate@SkylarkSignature
over to@SkylarkCallable
, we've been inadvertently fixing this bug, thereby breaking backward compatibility without an incompatible change flag.We've added
Param#legacyNamed
to prevent further breakages until we can control them with a flag (4baafac). For builtins that have already been migrated over, you may see errors like "unexpected keyword" or "parameter ... has no default value". If this impacts a significant number of users we could do a patch release to mark themlegacyNamed
. Otherwise it's better if users just update their code now since we want to be consistent with Python eventually anyway.The text was updated successfully, but these errors were encountered: