-
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
Use default when None
given to tag_class
attribute
#23547
Use default when None
given to tag_class
attribute
#23547
Conversation
Wouldn't this be a problem is the user actually wants to pass None to the attribute? |
I see, this is consistent with rules and repository_rules. Then LGTM! |
As noted, this is for consistency. #23548 also makes |
@Silic0nS0ldier Apart from consistency, what's the use case you have in mind for this? In the example above, both removing the argument and setting it to For build rules and repository rules, being able to use |
I have the same question as @fmeum. It's unclear to me what this is useful for. |
No specific use case in mind here, this was more of a knee-jerk response to noticing what is on the surface divergent behaviour for the As it stands right now, there is no need to support I do think that this divergence should be documented. Perhaps in |
Relates to #23547 `tag_class` is unique in a few ways to other functions that accept an attribute spec from the `attr` module. 1. It does not return a callable, but rather value containing metadata for `module_extension.tag_classes`. 2. The defined attributes outright reject `None` as a possible value, unlike `rule`, `aspect` and `repository_rule` which all fallback to the default as though no value were provided at all. Supporting `None` makes sense for the other callable results as constructs such as `**kwargs` and functions/macros with default `None` arguments often expose them to such values. Allowing `None` to implicitly mean "use default" is useful in those contexts. This is not the case for `tag _class`, which are interacted with in the extremely restricted context of `MODULE.bazel`. This PR seeks to document how `None` is treated by declared attributes now that behaviour is (intentionally) inconsistent. I also add links from builtin types such as `tag_class` to their factory function (`tag_class()`). Closes #23595. PiperOrigin-RevId: 676066782 Change-Id: Iacc7ca8b7b1560b2b79b7919ceb243504ff0e3cb
Relates to #23547 `tag_class` is unique in a few ways to other functions that accept an attribute spec from the `attr` module. 1. It does not return a callable, but rather value containing metadata for `module_extension.tag_classes`. 2. The defined attributes outright reject `None` as a possible value, unlike `rule`, `aspect` and `repository_rule` which all fallback to the default as though no value were provided at all. Supporting `None` makes sense for the other callable results as constructs such as `**kwargs` and functions/macros with default `None` arguments often expose them to such values. Allowing `None` to implicitly mean "use default" is useful in those contexts. This is not the case for `tag _class`, which are interacted with in the extremely restricted context of `MODULE.bazel`. This PR seeks to document how `None` is treated by declared attributes now that behaviour is (intentionally) inconsistent. I also add links from builtin types such as `tag_class` to their factory function (`tag_class()`). Closes #23595. PiperOrigin-RevId: 676066782 Change-Id: Iacc7ca8b7b1560b2b79b7919ceb243504ff0e3cb
With this, code like the following is valid.
Like with
rule
s andrepository_rule
s, the default (True
in the example) will be applied.