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: Mypy fix **kwargs type #15823

Merged
merged 1 commit into from Jul 28, 2021

Conversation

john-bodley
Copy link
Member

@john-bodley john-bodley commented Jul 21, 2021

SUMMARY

A follow up to #15757 (comment), per the Mypy documentation,

*args and **kwargs arguments can be annotated like so:

def stars(*args: int, **kwargs: float) -> None:
   # 'args' has type 'Tuple[int, ...]' (a tuple of ints)
   # 'kwargs' has type 'Dict[str, float]' (a dict of strs to floats)
   for arg in args:
       print(arg)
   for key, value in kwargs:
       print(key, value)

though kwargs is a Dict[str, ...] the typing of **kwargs is actually the dictionary value type.

TESTING INSTRUCTIONS

CI. Found all violations by running git grep "**kwargs: Dict".

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

@@ -683,7 +683,7 @@ def data_from_cache(self, cache_key: str) -> Response:
f".cache_screenshot",
log_to_statsd=False,
)
def cache_screenshot(self, pk: int, **kwargs: Dict[str, bool]) -> WerkzeugResponse:
def cache_screenshot(self, pk: int, **kwargs: Any) -> WerkzeugResponse:
Copy link
Member Author

Choose a reason for hiding this comment

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

The bool is incorrect given the logic below,

rison_dict = kwargs["rison"]
window_size = rison_dict.get("window_size")

i.e., clearly the type of the kwargs value (rison_dict) is of type Dict[str, ...] rather than bool.

Copy link
Member

Choose a reason for hiding this comment

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

can we maybe move rison_dict to named arg and get rid of kwargs?

Copy link
Member Author

Choose a reason for hiding this comment

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

@ktmud I think it's a tad more complex that that as I believe the information is being provided by the @rison decorator.

@codecov
Copy link

codecov bot commented Jul 21, 2021

Codecov Report

Merging #15823 (8c69cff) into master (ab4e3b9) will decrease coverage by 0.01%.
The diff coverage is 100.00%.

❗ Current head 8c69cff differs from pull request most recent head 0f9d05b. Consider uploading reports for the commit 0f9d05b to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master   #15823      +/-   ##
==========================================
- Coverage   76.91%   76.89%   -0.02%     
==========================================
  Files         984      984              
  Lines       51662    51622      -40     
  Branches     6991     6991              
==========================================
- Hits        39736    39697      -39     
+ Misses      11702    11701       -1     
  Partials      224      224              
Flag Coverage Δ
mysql 81.56% <100.00%> (ø)
postgres 81.56% <100.00%> (-0.03%) ⬇️
python 81.65% <100.00%> (-0.03%) ⬇️
sqlite 81.19% <100.00%> (ø)

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

Impacted Files Coverage Δ
superset/annotation_layers/annotations/api.py 84.96% <ø> (ø)
superset/reports/logs/api.py 94.11% <ø> (ø)
superset/charts/api.py 86.80% <100.00%> (ø)
superset/dashboards/api.py 92.95% <100.00%> (ø)
superset/utils/decorators.py 92.59% <100.00%> (-0.27%) ⬇️
superset/models/dashboard.py 74.77% <0.00%> (-2.22%) ⬇️
superset/common/query_context.py 81.42% <0.00%> (-0.40%) ⬇️
superset/utils/cache.py 74.28% <0.00%> (-0.25%) ⬇️
superset/reports/notifications/base.py 95.23% <0.00%> (-0.22%) ⬇️
... and 8 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 ab4e3b9...0f9d05b. Read the comment docs.

Copy link
Member

@ktmud ktmud left a comment

Choose a reason for hiding this comment

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

Lgtm

@john-bodley john-bodley merged commit 671b8f2 into apache:master Jul 28, 2021
@john-bodley john-bodley deleted the john-bodley--mypy-fix-kwargs branch July 28, 2021 16:59
opus-42 pushed a commit to opus-42/incubator-superset that referenced this pull request Nov 14, 2021
Co-authored-by: John Bodley <john.bodley@airbnb.com>
cccs-RyanS pushed a commit to CybercentreCanada/superset that referenced this pull request Dec 17, 2021
Co-authored-by: John Bodley <john.bodley@airbnb.com>
QAlexBall pushed a commit to QAlexBall/superset that referenced this pull request Dec 29, 2021
Co-authored-by: John Bodley <john.bodley@airbnb.com>
cccs-rc pushed a commit to CybercentreCanada/superset that referenced this pull request Mar 6, 2024
Co-authored-by: John Bodley <john.bodley@airbnb.com>
@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 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 size/S 🚢 1.3.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants