style(mypy): Spit-and-polish pass (#10001)

Co-authored-by: John Bodley <john.bodley@airbnb.com>
This commit is contained in:
John Bodley
2020-06-07 08:53:46 -07:00
committed by GitHub
parent 656cdfb867
commit 91517a56a3
56 changed files with 243 additions and 207 deletions

View File

@@ -341,11 +341,14 @@ class Database(
def get_reserved_words(self) -> Set[str]:
return self.get_dialect().preparer.reserved_words
def get_quoter(self) -> Callable:
def get_quoter(self) -> Callable[[str, Any], str]:
return self.get_dialect().identifier_preparer.quote
def get_df( # pylint: disable=too-many-locals
self, sql: str, schema: Optional[str] = None, mutator: Optional[Callable] = None
self,
sql: str,
schema: Optional[str] = None,
mutator: Optional[Callable[[pd.DataFrame], None]] = None,
) -> pd.DataFrame:
sqls = [str(s).strip(" ;") for s in sqlparse.parse(sql)]
@@ -450,7 +453,7 @@ class Database(
@cache_util.memoized_func(
key=lambda *args, **kwargs: "db:{}:schema:None:view_list",
attribute_in_key="id", # type: ignore
attribute_in_key="id",
)
def get_all_view_names_in_database(
self,

View File

@@ -240,7 +240,7 @@ class Dashboard( # pylint: disable=too-many-instance-attributes
self.json_metadata = value
@property
def position(self) -> Dict:
def position(self) -> Dict[str, Any]:
if self.position_json:
return json.loads(self.position_json)
return {}
@@ -315,7 +315,7 @@ class Dashboard( # pylint: disable=too-many-instance-attributes
old_to_new_slc_id_dict: Dict[int, int] = {}
new_timed_refresh_immune_slices = []
new_expanded_slices = {}
new_filter_scopes: Dict[str, Dict] = {}
new_filter_scopes = {}
i_params_dict = dashboard_to_import.params_dict
remote_id_slice_map = {
slc.params_dict["remote_id"]: slc
@@ -351,7 +351,7 @@ class Dashboard( # pylint: disable=too-many-instance-attributes
# are converted to filter_scopes
# but dashboard create from import may still have old dashboard filter metadata
# here we convert them to new filter_scopes metadata first
filter_scopes: Dict = {}
filter_scopes = {}
if (
"filter_immune_slices" in i_params_dict
or "filter_immune_slice_fields" in i_params_dict
@@ -415,7 +415,7 @@ class Dashboard( # pylint: disable=too-many-instance-attributes
@classmethod
def export_dashboards( # pylint: disable=too-many-locals
cls, dashboard_ids: List
cls, dashboard_ids: List[int]
) -> str:
copied_dashboards = []
datasource_ids = set()

View File

@@ -81,7 +81,7 @@ class ImportMixin:
for u in cls.__table_args__ # type: ignore
if isinstance(u, UniqueConstraint)
]
unique.extend( # type: ignore
unique.extend(
{c.name} for c in cls.__table__.columns if c.unique # type: ignore
)
return unique

View File

@@ -36,7 +36,7 @@ from superset.tasks.thumbnails import cache_chart_thumbnail
from superset.utils import core as utils
if is_feature_enabled("SIP_38_VIZ_REARCHITECTURE"):
from superset.viz_sip38 import BaseViz, viz_types # type: ignore
from superset.viz_sip38 import BaseViz, viz_types
else:
from superset.viz import BaseViz, viz_types # type: ignore

View File

@@ -14,7 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from typing import Any, Optional, Type
from typing import Any, Dict, List, Optional, Type
from sqlalchemy import types
from sqlalchemy.sql.sqltypes import Integer
@@ -29,7 +29,7 @@ class TinyInteger(Integer):
A type for tiny ``int`` integers.
"""
def python_type(self) -> Type:
def python_type(self) -> Type[int]:
return int
@classmethod
@@ -42,7 +42,7 @@ class Interval(TypeEngine):
A type for intervals.
"""
def python_type(self) -> Optional[Type]:
def python_type(self) -> Optional[Type[Any]]:
return None
@classmethod
@@ -55,7 +55,7 @@ class Array(TypeEngine):
A type for arrays.
"""
def python_type(self) -> Optional[Type]:
def python_type(self) -> Optional[Type[List[Any]]]:
return list
@classmethod
@@ -68,7 +68,7 @@ class Map(TypeEngine):
A type for maps.
"""
def python_type(self) -> Optional[Type]:
def python_type(self) -> Optional[Type[Dict[Any, Any]]]:
return dict
@classmethod
@@ -81,7 +81,7 @@ class Row(TypeEngine):
A type for rows.
"""
def python_type(self) -> Optional[Type]:
def python_type(self) -> Optional[Type[Any]]:
return None
@classmethod