8000 Fix #4926 - support for float options from addons by triztian · Pull Request #4927 · mitmproxy/mitmproxy · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

triztian
Copy link
@triztian triztian commented Nov 20, 2021

Description

Add support for option float types.

Checklist

  • I have updated tests where applicable.
  • I have added an entry to the CHANGELOG.
  • Ran tox -e py
  • Ran tox -e flake8

Fixed functionality:

mitmproxy-issue-4926-fix

@triztian triztian force-pushed the issue/4926-float-options branch from 2d50b60 to 1b3e5f8 Compare November 21, 2021 02:18
Copy link
Member
@mhils mhils left a 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:
Copy link
Member

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?

Copy link
Author

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

Copy link
Member

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.

@triztian triztian force-pushed the issue/4926-float-options branch from b3f82fe to 9646aa2 Compare November 26, 2021 07:04
Copy link
Member
@mhils mhils left a 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:
Copy link
Member

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:
Copy link
Member

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
Copy link
Member

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?

@mhils mhils force-pushed the main branch 3 times, most recently from f0383ea to 7352811 Compare March 19, 2022 16:20
@mhils mhils marked this pull request as draft March 30, 2022 12:34
@mhils mhils force-pushed the main branch 4 times, most recently from 60396c7 to 5a135df Compare February 5, 2025 22:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0