Skip to content
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

refactor(utils): replace strtobool with parse_boolean_string #14494

Merged
merged 1 commit into from
May 6, 2021

Conversation

villebro
Copy link
Member

@villebro villebro commented May 5, 2021

SUMMARY

When adding some boolean string parsing for #14483 , I figured we could use this in all places where distutils.util.strtobool is used to pick up some variations that strtobool can't handle, like upper/mixedcase.

This is the new util:

def parse_boolean_string(bool_str: Optional[str]) -> bool:
"""
Convert a string representation of a true/false value into a boolean
>>> parse_boolean_string(None)
False
>>> parse_boolean_string('false')
False
>>> parse_boolean_string('true')
True
>>> parse_boolean_string('False')
False
>>> parse_boolean_string('True')
True
>>> parse_boolean_string('foo')
False
>>> parse_boolean_string('0')
False
>>> parse_boolean_string('1')
True
:param bool_str: string representation of a value that is assumed to be boolean
:return: parsed boolean value
"""
if bool_str is None:
return False
try:
return bool(strtobool(bool_str.lower()))
except ValueError:
return False

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TEST PLAN

ADDITIONAL INFORMATION

  • Has associated issue:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@codecov
Copy link

codecov bot commented May 5, 2021

Codecov Report

Merging #14494 (68058b0) into master (b030c98) will decrease coverage by 0.05%.
The diff coverage is 76.16%.

❗ Current head 68058b0 differs from pull request most recent head fcc9251. Consider uploading reports for the commit fcc9251 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master   #14494      +/-   ##
==========================================
- Coverage   77.12%   77.06%   -0.06%     
==========================================
  Files         953      958       +5     
  Lines       48189    48242      +53     
  Branches     6051     6062      +11     
==========================================
+ Hits        37166    37179      +13     
- Misses      10822    10862      +40     
  Partials      201      201              
Flag Coverage Δ
hive 80.80% <ø> (ø)
javascript 72.01% <76.16%> (+0.07%) ⬆️
mysql 81.06% <ø> (ø)
postgres 81.09% <ø> (ø)
presto ?
python 81.47% <ø> (-0.16%) ⬇️
sqlite 80.70% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
superset-frontend/src/CRUD/Field.jsx 83.33% <ø> (ø)
...tend/src/SqlLab/components/SouthPane/SouthPane.tsx 79.54% <ø> (ø)
...rset-frontend/src/components/InfoTooltip/index.tsx 100.00% <ø> (ø)
superset-frontend/src/components/Modal/Modal.tsx 100.00% <ø> (ø)
...shboard/components/filterscope/FilterFieldItem.jsx 100.00% <ø> (ø)
...-frontend/src/explore/components/ControlHeader.jsx 85.18% <ø> (ø)
...rontend/src/explore/components/EmbedCodeButton.jsx 80.76% <ø> (ø)
...nd/src/explore/components/ExploreViewContainer.jsx 2.33% <ø> (ø)
...rc/explore/components/controls/ViewportControl.jsx 82.60% <ø> (ø)
...rontend/src/visualizations/FilterBox/FilterBox.jsx 56.60% <ø> (ø)
... and 33 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b030c98...fcc9251. Read the comment docs.

Copy link
Member

@michael-s-molina michael-s-molina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@villebro villebro merged commit 4ac90dd into apache:master May 6, 2021
cccs-RyanS pushed a commit to CybercentreCanada/superset that referenced this pull request Dec 17, 2021
QAlexBall pushed a commit to QAlexBall/superset that referenced this pull request Dec 29, 2021
cccs-rc pushed a commit to CybercentreCanada/superset that referenced this pull request Mar 6, 2024
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.3.0 labels Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels preset-io size/XS 🚢 1.3.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants