-
Notifications
You must be signed in to change notification settings - Fork 14.3k
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.examples module #9469
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ | |
import os | ||
import zlib | ||
from io import BytesIO | ||
from typing import Set | ||
from typing import Any, Dict, List, Set | ||
from urllib import request | ||
|
||
from superset import app, db | ||
|
@@ -41,7 +41,7 @@ | |
misc_dash_slices: Set[str] = set() # slices assembled in a 'Misc Chart' dashboard | ||
|
||
|
||
def update_slice_ids(layout_dict, slices): | ||
def update_slice_ids(layout_dict: Dict[Any, Any], slices: List[Slice]) -> None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not necessary a change that needs to be done here, but with proper typing, we don't necessarily need to include types in names as much in the future. Here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @villebro I agree. I've never been a fan of variables the |
||
charts = [ | ||
component | ||
for component in layout_dict.values() | ||
|
@@ -53,21 +53,23 @@ def update_slice_ids(layout_dict, slices): | |
chart_component["meta"]["chartId"] = int(slices[i].id) | ||
|
||
|
||
def merge_slice(slc): | ||
def merge_slice(slc: Slice) -> None: | ||
o = db.session.query(Slice).filter_by(slice_name=slc.slice_name).first() | ||
if o: | ||
db.session.delete(o) | ||
db.session.add(slc) | ||
db.session.commit() | ||
|
||
|
||
def get_slice_json(defaults, **kwargs): | ||
def get_slice_json(defaults: Dict[Any, Any], **kwargs: Any) -> str: | ||
d = defaults.copy() | ||
d.update(kwargs) | ||
return json.dumps(d, indent=4, sort_keys=True) | ||
|
||
|
||
def get_example_data(filepath, is_gzip=True, make_bytes=False): | ||
def get_example_data( | ||
filepath: str, is_gzip: bool = True, make_bytes: bool = False | ||
) -> BytesIO: | ||
content = request.urlopen(f"{BASE_URL}{filepath}?raw=true").read() | ||
if is_gzip: | ||
content = zlib.decompress(content, zlib.MAX_WBITS | 16) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
from typing import Dict, Optional, Tuple | ||
|
||
import pandas as pd | ||
from sqlalchemy import BigInteger, Date, DateTime, String | ||
|
@@ -32,7 +33,9 @@ | |
) | ||
|
||
|
||
def load_multiformat_time_series(only_metadata=False, force=False): | ||
def load_multiformat_time_series( | ||
only_metadata: bool = False, force: bool = False | ||
) -> None: | ||
"""Loading time series data from a zip file in the repo""" | ||
tbl_name = "multiformat_time_series" | ||
database = get_example_database() | ||
|
@@ -70,15 +73,15 @@ def load_multiformat_time_series(only_metadata=False, force=False): | |
obj = TBL(table_name=tbl_name) | ||
obj.main_dttm_col = "ds" | ||
obj.database = database | ||
dttm_and_expr_dict = { | ||
"ds": [None, None], | ||
"ds2": [None, None], | ||
"epoch_s": ["epoch_s", None], | ||
"epoch_ms": ["epoch_ms", None], | ||
"string2": ["%Y%m%d-%H%M%S", None], | ||
"string1": ["%Y-%m-%d^%H:%M:%S", None], | ||
"string0": ["%Y-%m-%d %H:%M:%S.%f", None], | ||
"string3": ["%Y/%m/%d%H:%M:%S.%f", None], | ||
dttm_and_expr_dict: Dict[str, Tuple[Optional[str], None]] = { | ||
"ds": (None, None), | ||
"ds2": (None, None), | ||
"epoch_s": ("epoch_s", None), | ||
"epoch_ms": ("epoch_ms", None), | ||
"string2": ("%Y%m%d-%H%M%S", None), | ||
"string1": ("%Y-%m-%d^%H:%M:%S", None), | ||
"string0": ("%Y-%m-%d %H:%M:%S.%f", None), | ||
"string3": ("%Y/%m/%d%H:%M:%S.%f", None), | ||
Comment on lines
+76
to
+84
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
} | ||
for col in obj.columns: | ||
dttm_and_expr = dttm_and_expr_dict[col.column_name] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These examples were clearly wrong given the return type and thus I removed them.