-
Notifications
You must be signed in to change notification settings - Fork 160
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
Add BooleanArtifact
#905
Add BooleanArtifact
#905
Conversation
return BooleanArtifact(True) | ||
elif value.lower() == "false": | ||
return BooleanArtifact(False) | ||
raise ValueError(f"Cannot convert string literal '{value}' to BooleanArtifact") |
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.
should this return None
or raise an exception?
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 vote for raise an exception.
If the user's code assumes that the parse always succeeds and then it fails, returning None will (most likely) cause an exception to be raised by code that consumes this output. Then it will be the user's responsibility to trace it back to here, so we might as well do it for them.
|
||
@define | ||
class BooleanArtifact(BaseArtifact): | ||
value: bool = field(converter=bool, metadata={"serializable": True}) |
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.
passing in a value on init will get coerced into a bool
, whereas using parse_bool
will check for the literal true or false. should that check be done on init instead?
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 having these two methods of creating a BooleanArtifact
seems reasonable. The default (init) way being a little more flexible, but still offering a stricter option for strings specifically.
If you don't offer the bool coercion option and the use case comes up, then what would that look like? like this: BooleanArtifact(bool(x))
? I suppose that's easy enough, but BooleanArtifact(x)
is a little better. Actually, the parse_bool
wouldn't work for a literal True
or False
, so I definitely vote for keeping both creation options.
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.
the init method will always convert the input to a boolean. this can lead to suprising behavior sometimes where BooleanArtifact("False").value is True
. parse_bool
is to parse string literal values as a convenience. thinking about it now, seems more "pythonic" to keep the init as to whatever python interprets as a bool, and use parse_bool
to parse string literal values as a convenience
Codecov ReportAttention: Patch coverage is
📢 Thoughts on this report? Let us know! |
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.
Nice work!
I know there's not much to test, but wanna add unit tests?
return BooleanArtifact(True) | ||
elif value.lower() == "false": | ||
return BooleanArtifact(False) | ||
raise ValueError(f"Cannot convert string literal '{value}' to BooleanArtifact") |
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 vote for raise an exception.
If the user's code assumes that the parse always succeeds and then it fails, returning None will (most likely) cause an exception to be raised by code that consumes this output. Then it will be the user's responsibility to trace it back to here, so we might as well do it for them.
|
||
@define | ||
class BooleanArtifact(BaseArtifact): | ||
value: bool = field(converter=bool, metadata={"serializable": True}) |
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 having these two methods of creating a BooleanArtifact
seems reasonable. The default (init) way being a little more flexible, but still offering a stricter option for strings specifically.
If you don't offer the bool coercion option and the use case comes up, then what would that look like? like this: BooleanArtifact(bool(x))
? I suppose that's easy enough, but BooleanArtifact(x)
is a little better. Actually, the parse_bool
wouldn't work for a literal True
or False
, so I definitely vote for keeping both creation options.
484670c
to
daf0783
Compare
artifact that is explicitly
True
orFalse
.i want to output a boolean from a
Task
and do something with that information later, and checking the string value of aTextArtifact
is clunky.incremental update to support #904