-
-
Notifications
You must be signed in to change notification settings - Fork 643
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
Support overriding param types for rule code #16929
Conversation
# Rust tests and lints will be skipped. Delete if not intended. [ci skip-rust] # Building wheels and fs_util will be skipped. Delete if not intended. [ci skip-build-wheels]
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.
Sg, given that this is very niche
Will wait for another maintainers review since this is a "wide" change |
# Rust tests and lints will be skipped. Delete if not intended. [ci skip-rust] # Building wheels and fs_util will be skipped. Delete if not intended. [ci skip-build-wheels]
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.
This looks safe to me, as if you don't use this feature it should do the same as before.
Only thing I perhaps don't understand is the value of the overriden type.
src/python/pants/engine/rules.py
Outdated
parameter_types = tuple( | ||
_ensure_type_annotation( | ||
param_type_overrides[parameter] | ||
if parameter in param_type_overrides |
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 think this bypasses the type check performed by _ensure_type_annotation
, maybe check that in the previous for loop?
for parameter, value in param_type_overrides.items():
...
@kaos by "value" do you mean the benefit, or the concrete value type of the mapping? |
the concrete type I think. Also I'm not sure I've come across the need for the benefit, but my mind is crazy enough to appreciate the flexibility up-front and find the use for it later :P (I can imagine there's one when you're trying to implement PluginOption and the like) |
I can give two examples:
|
# Rust tests and lints will be skipped. Delete if not intended. [ci skip-rust] # Building wheels and fs_util will be skipped. Delete if not intended. [ci skip-build-wheels]
Is this effectively using a |
Bingo! Although it'd be a subset of |
It could be a separate Is that worth sketching out as an alternative? It should be easy to implement: similar to this line (which installs a |
I think this is much more general and likely easier to grok? See also use-case 2. |
Use case 2 also appears to be a
Possibly... note that this is only actually type safe if the substituted parameter is a subclass of the actual declared type. It might be worth validating that? |
That's definitely the sane way to think about it. However, much like It's not any more-or-less typesafe than, say:
I'm not against it, but we're forcing our hand on some inheritance (which #16926 is particularly relevant as it will be the first "type" we do this substitution on) |
@stuhood would you prefer I prefix with underscore so we can explore it further in Pants repo (and feel comfortable removing it possibly later?) |
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.
@stuhood would you prefer I prefix with underscore so we can explore it further in Pants repo (and feel comfortable removing it possibly later?)
Yes. Please leave a comment explaining the connection to @union
s and subtyping.
# Rust tests and lints will be skipped. Delete if not intended. [ci skip-rust] # Building wheels and fs_util will be skipped. Delete if not intended. [ci skip-build-wheels]
The main use-case is runtime-typed parameters (for use in "helper"/"inner" rules).
[ci skip-rust]
[ci skip-build-wheels]