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

style(mypy): Enforcing typing for superset module #9943

Conversation

john-bodley
Copy link
Member

@john-bodley john-bodley commented May 29, 2020

SUMMARY

Yay! After starting this endeavor over three months ago with #9138, this PR adds mypy type enforcement for the remainder of the superset package, thus signifying the final typing PR (for now at least).

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TEST PLAN

CI.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Changes UI
  • Requires DB Migration.
  • Confirm DB Migration upgrade and downgrade tested.
  • Introduces new feature or API
  • Removes existing feature or API

@@ -53,7 +53,7 @@ order_by_type = false
ignore_missing_imports = true
no_implicit_optional = true

[mypy-superset.bin.*,superset.charts.*,superset.commands.*,superset.common.*,superset.connectors.*,superset.dao.*,superset.dashboards.*,superset.datasets.*,superset.db_engine_specs.*,superset.db_engines.*,superset.examples.*,superset.migrations.*,superset.models.*,uperset.queries.*,superset.security.*,superset.sql_validators.*,superset.tasks.*,superset.translations.*,superset.utils.*,superset.views.chart.*,superset.views.dashboard.*,superset.views.database.*]
[mypy-superset,superset.app,superset.bin.*,superset.charts.*,superset.cli,superset.commands.*,superset.common.*,superset.config,superset.connectors.*,superset.constants,superset.dataframe,superset.dao.*,superset.dashboards.*,superset.datasets.*,superset.db_engine_specs.*,superset.db_engines.*,superset.errors,superset.examples.*,superset.exceptions,superset.extensions,superset.forms,superset.jinja_context,superset.legacy,superset.migrations.*,superset.models.*,superset.result_set,superset.queries.*,superset.security.*,superset.sql_lab,superset.sql_parse,superset.sql_validators.*,superset.stats_logger,superset.tasks.*,superset.translations.*,superset.typing,superset.utils.*,superset.views.chart.*,superset.views.dashboard.*,superset.views.database.*,superset.viz,superset.viz_sip38]
Copy link
Member Author

Choose a reason for hiding this comment

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

Note after this PR and #9939 are merged this should be updated to read,

[mypy-superset.*]

@john-bodley john-bodley force-pushed the john-bodley--mypy-enforcement-remainder branch from 20e76e1 to 9a5b77f Compare May 29, 2020 07:04
@codecov-commenter
Copy link

codecov-commenter commented May 29, 2020

Codecov Report

Merging #9943 into master will increase coverage by 0.05%.
The diff coverage is 83.08%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #9943      +/-   ##
==========================================
+ Coverage   71.31%   71.37%   +0.05%     
==========================================
  Files         585      585              
  Lines       30887    30933      +46     
  Branches     3236     3246      +10     
==========================================
+ Hits        22027    22078      +51     
+ Misses       8750     8746       -4     
+ Partials      110      109       -1     
Flag Coverage Δ
#cypress 54.06% <ø> (+0.22%) ⬆️
#javascript 59.39% <ø> (-0.02%) ⬇️
#python 71.54% <83.08%> (+0.01%) ⬆️
Impacted Files Coverage Δ
superset/viz_sip38.py 0.00% <0.00%> (ø)
superset/jinja_context.py 80.95% <40.00%> (-0.78%) ⬇️
superset/viz.py 71.94% <79.33%> (-0.03%) ⬇️
superset/app.py 81.51% <80.76%> (+0.15%) ⬆️
superset/forms.py 95.45% <87.50%> (ø)
superset/cli.py 40.06% <95.00%> (+0.20%) ⬆️
superset/config.py 89.75% <100.00%> (+0.08%) ⬆️
superset/exceptions.py 100.00% <100.00%> (ø)
superset/extensions.py 95.45% <100.00%> (+0.10%) ⬆️
superset/sql_lab.py 78.35% <100.00%> (+0.09%) ⬆️
... and 14 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 b296a0f...6bcbf55. Read the comment docs.

@john-bodley john-bodley force-pushed the john-bodley--mypy-enforcement-remainder branch 5 times, most recently from 374aeca to bb4eb34 Compare May 29, 2020 08:16
@john-bodley john-bodley changed the title style(mypy): Enforcing typing for superset style(mypy): Enforcing typing for superset module May 29, 2020
@john-bodley
Copy link
Member Author

john-bodley commented Jun 1, 2020

@villebro et al. would you mind taking a look at this PR?

def __call__(self, *args, **kwargs):
with flask_app.app_context():
def __call__(self, *args: Any, **kwargs: Any) -> Any:
with flask_app.app_context(): # type: ignore
Copy link
Contributor

Choose a reason for hiding this comment

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

This probably is for later, we should look into using the flask stubs in typeshed

Copy link
Member Author

Choose a reason for hiding this comment

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

@serenajiang mypy does use these stubs. I presume the Flask types aren't fully flushed out. I plan on creating a follow up PR which will check for erroneous # type: ignore comments which then can be removed as mypy continues to evolve.

superset/viz.py Outdated
@@ -559,7 +563,7 @@ class TableViz(BaseViz):
is_timeseries = False
enforce_numerical_metrics = False

def should_be_timeseries(self):
def should_be_timeseries(self) -> Optional[bool]:
Copy link
Contributor

Choose a reason for hiding this comment

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

In this case, if should_be_timeseries() is None, does that mean this is False? It could be good to cast the results to bool to avoid the weird sorts of results that occur with short circuiting + .get. Then, we can replace most of the Optional[bool] types with bool.

superset/viz.py Outdated
procs: Dict[int, pd.DataFrame],
level: int = -1,
dims: Optional[Tuple[str, ...]] = None,
time: Optional[Any] = None,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
time: Optional[Any] = None,
time: Any = None,

@john-bodley john-bodley force-pushed the john-bodley--mypy-enforcement-remainder branch from bb4eb34 to 6bcbf55 Compare June 2, 2020 18:29
Copy link
Member

@villebro villebro left a comment

Choose a reason for hiding this comment

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

One small comment not directly related to changes in this PR

@@ -2367,7 +2382,7 @@ def query_obj(self):
d["columns"] = gb
return d

def get_js_columns(self, d):
def get_js_columns(self, d: Dict[str, Any]) -> Dict[str, Any]:
Copy link
Member

Choose a reason for hiding this comment

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

d looks like a bad variable name. I thought these were forbidden in .pylintrc?

Copy link
Member Author

@john-bodley john-bodley Jun 2, 2020

Choose a reason for hiding this comment

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

@villebro I'm not sure if you're aware, but numerous files have pylint checks and warnings (not errors) disabled including viz.py per the line:

# pylint: disable=C,R,W

Note the plan is to address this in SIP-46. I'm not quite mentally prepared for that saga yet as the typing work has left me a tad battered and bruised.

Copy link
Member

Choose a reason for hiding this comment

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

😄 I'm sure it has, kudos for this work! I think we need to bump pylint first, as the current version isn't compatible with 3.7. I'm looking to see if there's interest in the community to help with that effort, as it might be a good task to get acquainted with the codebase.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed regarding bumping pylint (this is actually mentioned in the SIP) as I ran into an issue trying to use a newer feature. I'm not sure if we can automate this, but periodically I think it's good that we go through and bump all our dependencies which should help us be more nimble to accommodate us supporting more recent Python versions.

@john-bodley john-bodley merged commit 244677c into apache:master Jun 3, 2020
@john-bodley john-bodley deleted the john-bodley--mypy-enforcement-remainder branch June 3, 2020 22:30
auxten pushed a commit to auxten/incubator-superset that referenced this pull request Nov 20, 2020
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.37.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 size/XL 🚢 0.37.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants