-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Fix #4926 - support for float options from addons #4927
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
2d50b60
to
1b3e5f8
Compare
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.
Thanks for the PR! This looks good already, some comments below.
@@ -45,7 +45,10 @@ def get_widget(self): | |||
if self.opt.typespec == bool: | |||
displayval = "true" if val else "false" | |||
elif not val: | |||
displayval = "" | |||
if self.opt.typespec == float: |
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.
Could you explain this change? In particular, why do we need to treat floats and ints differently here?
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.
@mhils what I noticed was that int and float options with a default value of 0
or 0.0
displayed the empty string. I think that the actual 0
or 0.0
should be displayed but since I was working only on floats I'd decided to leave int
as is and instead handle the case when its a float to display the string value of it.
If you're ok with it I can make it so that the 0
and 0.0
is displayed for both int and float respectively when their values are 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.
That makes sense, thanks. Let's change that condition in line 47 to elif val in (None, ""):
, then we have proper treatment for everything else.
b3f82fe
to
9646aa2
Compare
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.
Thank for updating this and sorry for the slow turnaround! :)
@@ -45,7 +45,10 @@ def get_widget(self): | |||
if self.opt.typespec == bool: | |||
displayval = "true" if val else "false" | |||
elif not val: | |||
displayval = "" | |||
if self.opt.typespec == float: |
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.
That makes sense, thanks. Let's change that condition in line 47 to elif val in (None, ""):
, then we have proper treatment for everything else.
return int(optstr) | ||
elif typespec in (float, typing.Optional[float]): | ||
return float(optstr) | ||
else: |
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 condition cannot be hit, no?
typename = str(typespec).split("'")[1] | ||
raise exceptions.OptionsError(f"Not an {typename}: {optstr}") | ||
else: | ||
return None |
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.
Do we intentionally discard invalid values for optionals here? Just from the source it looks like they should raise an error as well?
f0383ea
to
7352811
Compare
60396c7
to
5a135df
Compare
Description
Add support for option
float
types.Checklist
tox -e py
tox -e flake8
Fixed functionality: