Skip to content

Fix #4926 - support for float options from addons - #4927

Draft
triztian wants to merge 7 commits into
mitmproxy:mainfrom
triztian:issue/4926-float-options
Draft

triztian wants to merge 7 commits into
mitmproxy:mainfrom
triztian:issue/4926-float-options

Conversation

@triztian

@triztian triztian commented Nov 20, 2021 •

Copy link
Copy Markdown

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

@mhils mhils left a comment

Copy link
Copy Markdown
Member

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.

Comment thread CONTRIBUTING.md Resolved
Comment thread mitmproxy/optmanager.py Resolved
displayval = "true" if val else "false"
elif not val:
displayval = ""
if self.opt.typespec == float:

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

@mhils mhils left a comment

Copy link
Copy Markdown
Member

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! :)

displayval = "true" if val else "false"
elif not val:
displayval = ""
if self.opt.typespec == float:

Copy link
Copy Markdown
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.

Comment thread mitmproxy/optmanager.py
return int(optstr)
elif typespec in (float, typing.Optional[float]):
return float(optstr)
else:

Copy link
Copy Markdown
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?

Comment thread mitmproxy/optmanager.py
typename = str(typespec).split("'")[1]
raise exceptions.OptionsError(f"Not an {typename}: {optstr}")
else:
return None

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

This branch has not been deployed

No deployments
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