-
Notifications
You must be signed in to change notification settings - Fork 13
Add validator to handle extractable features types #107
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
base: main
Are you sure you want to change the base?
Conversation
ccc5489 to
e236c8a
Compare
| from osprey.engine.language_types.entities import EntityT | ||
| from osprey.engine.udf.type_helpers import to_display_str | ||
|
|
||
| from ..base_validator import SourceValidator |
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.
use the full osprey.engine.* path for consistency.
| To use a custom type without extraction, prefix the variable name with `_` to make | ||
| it a local variable: | ||
| _VC1 = CustomUdf(entity=TestUser) # OK - not extracted | ||
| VC1 = CustomUdf(entity=TestUser) # ERROR - would be extracted |
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.
coming in without too much context, and I do remember this is a thing we do, but its kinda a hack in the first place, assigning some semantic meaning to the name of a variable is pretty unexpected.
Definitely think this validator is a positive, but we should think about what we want a better API to look like in the future (in_the_backlog.gif)
| non_none_args = [a for a in args if a is not type(None)] # noqa: E721 | ||
| # Optional is a Union with exactly one non-None type | ||
| if len(non_none_args) == 1: | ||
| return _is_extractable_type(non_none_args[0]) |
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.
cool recursion
| # Check Optional[T] (which is Union[T, None] at runtime) | ||
| if typing_inspect.is_union_type(t): | ||
| args = typing_inspect.get_args(t) | ||
| non_none_args = [a for a in args if a is not type(None)] # noqa: E721 |
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.
Technically this also allows Union[T], but I guess we dont really care
UDFs that return a custom type will break the UI's extracted features -> values mapping, so we need a validator that checks that we aren't implementing any rules that return a custom type.