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

chore: upgrade mypy and add type guards #16227

Merged
merged 3 commits into from
Aug 14, 2021

Conversation

villebro
Copy link
Member

SUMMARY

This is a follow-up to #16194 to introduce support for TypeGuard introduced in Python 3.10.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

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

Comment on lines -1309 to +1308
return cast(str, metric)
return metric # type: ignore
Copy link
Member Author

Choose a reason for hiding this comment

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

For some reason mypy didn't pick up that Union[str, AdhocMetric] becomes str after we do is_adhoc_metric(metric) above

@villebro villebro force-pushed the villebro/mypy-0.910 branch from f19ccdc to 66c5f5c Compare August 12, 2021 08:37
hooks:
- id: mypy
additional_dependencies: [types-all]
Copy link
Member Author

Choose a reason for hiding this comment

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

This was the cleanest solution I could come up with to automatically populate stubs for mypy pre-commit hooks: pre-commit-ci/issues#69 (comment)

Copy link
Member

Choose a reason for hiding this comment

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

@villebro this is what we did at Airbnb as well. It's a real shame that Mypy doesn't install these by default if needed.

@codecov
Copy link

codecov bot commented Aug 12, 2021

Codecov Report

Merging #16227 (09ca27f) into master (b61c34f) will decrease coverage by 0.21%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #16227      +/-   ##
==========================================
- Coverage   76.71%   76.49%   -0.22%     
==========================================
  Files         996      996              
  Lines       53080    53080              
  Branches     6739     6739              
==========================================
- Hits        40721    40605     -116     
- Misses      12130    12246     +116     
  Partials      229      229              
Flag Coverage Δ
hive ?
mysql 81.53% <100.00%> (-0.05%) ⬇️
postgres 81.59% <100.00%> (ø)
presto ?
python 81.68% <100.00%> (-0.43%) ⬇️
sqlite 81.19% <100.00%> (ø)

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

Impacted Files Coverage Δ
superset/tasks/schedules.py 76.36% <ø> (ø)
superset/typing.py 97.77% <100.00%> (ø)
superset/utils/async_query_manager.py 82.24% <100.00%> (ø)
superset/utils/core.py 88.97% <100.00%> (-0.14%) ⬇️
superset/db_engines/hive.py 0.00% <0.00%> (-82.15%) ⬇️
superset/db_engine_specs/hive.py 69.80% <0.00%> (-16.87%) ⬇️
superset/db_engine_specs/presto.py 83.47% <0.00%> (-6.49%) ⬇️
superset/views/database/mixins.py 81.03% <0.00%> (-1.73%) ⬇️
superset/connectors/sqla/models.py 88.04% <0.00%> (-1.66%) ⬇️
superset/db_engine_specs/base.py 88.00% <0.00%> (-0.37%) ⬇️
... and 3 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 b61c34f...09ca27f. Read the comment docs.

hooks:
- id: mypy
additional_dependencies: [types-all]
Copy link
Member

Choose a reason for hiding this comment

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

@villebro this is what we did at Airbnb as well. It's a real shame that Mypy doesn't install these by default if needed.

requirements/base.in Outdated Show resolved Hide resolved
@@ -57,7 +57,7 @@ class AdhocMetricColumn(TypedDict, total=False):
class AdhocMetric(TypedDict, total=False):
aggregate: str
column: Optional[AdhocMetricColumn]
expressionType: str
expressionType: Literal["SIMPLE", "SQL"]
Copy link
Member

Choose a reason for hiding this comment

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

I guess this is screaming out to be an enum. Definitely a future TODO.

Copy link
Member Author

@villebro villebro Aug 13, 2021

Choose a reason for hiding this comment

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

Good idea. In the next iteration I'll see if I can convert some of these Literal's to Enums. But it may well be that this is the most accurate representation of this type, as we want to indicate that this is a string that can only take on two values (equivalent of TypeScript's expressionType: 'SIMPLE' | 'SQL')

@villebro villebro merged commit d46dc9a into apache:master Aug 14, 2021
amitmiran137 pushed a commit that referenced this pull request Aug 16, 2021
…gies

* upstream/master: (64 commits)
  check roles before fetching reports (#16260)
  chore: upgrade mypy and add type guards (#16227)
  fix: pivot columns with ints for name (#16259)
  chore(pylint): Bump Pylint to 2.9.6 (#16146)
  fix examples tab for dashboard (#16253)
  chore: bump superset-ui packages to 0.17.84 (#16251)
  chore: Shows the dataset description in the gallery dropdown (#16200)
  fix(Dashboard): Omnibar dropdown visibility and keyboard commands (#16168)
  chore: bump py version for integration test (#16213)
  fix: skip perms on query context update (#16250)
  refactor: external metadata fetch API (#16193)
  feat(dao): admin can remove self from object owners (#15149)
  fix(dashboard): cross filter chart highlight when filters badge icon clicked (#16233)
  fix: validate_parameters and query (#16241)
  fix: Remove Advanced Analytics tag for 2 charts (#16240)
  Revert "feat: Changing Dataset names (#16199)" (#16235)
  feat: Allow users to connect via legacy SQLA form (#16201)
  fix: remove encryption from db params (#16214)
  fix(Explore): Show the tooltip only when label does not fit the container in METRICS/FILTERS/GROUP BY/SORT BY of the DATA panel (#16060)
  Show/hide tooltips (#16192)
  ...

# Conflicts:
#	superset/tasks/caching/cache_strategy.py
opus-42 pushed a commit to opus-42/incubator-superset that referenced this pull request Nov 14, 2021
QAlexBall pushed a commit to QAlexBall/superset that referenced this pull request Dec 28, 2021
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.4.0 labels Mar 13, 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/M 🚢 1.4.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants