Skip to content

Commit

Permalink
chore(pylint): Enable useless-suppression check (#16388)
Browse files Browse the repository at this point in the history
Co-authored-by: John Bodley <john.bodley@airbnb.com>
  • Loading branch information
john-bodley and John Bodley authored Aug 23, 2021
1 parent 970d762 commit 7e4c940
Show file tree
Hide file tree
Showing 66 changed files with 128 additions and 226 deletions.
3 changes: 2 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ confidence=
# either give multiple identifier separated by comma (,) or put this option
# multiple time (only on the command line, not in the configuration file where
# it should appear only once). See also the "--disable" option for examples.
#enable=
enable=
useless-suppression,

# Disable the message, report, category or checker with the given id(s). You
# can either give multiple identifiers separated by comma (,) or put this
Expand Down
1 change: 0 additions & 1 deletion superset/charts/commands/importers/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class ImportChartsCommand(BaseCommand):
until it finds one that matches.
"""

# pylint: disable=unused-argument
def __init__(self, contents: Dict[str, str], *args: Any, **kwargs: Any):
self.contents = contents
self.args = args
Expand Down
4 changes: 1 addition & 3 deletions superset/charts/post_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,7 @@ def list_unique_values(series: pd.Series) -> str:
}


def pivot_table_v2( # pylint: disable=too-many-branches
df: pd.DataFrame, form_data: Dict[str, Any]
) -> pd.DataFrame:
def pivot_table_v2(df: pd.DataFrame, form_data: Dict[str, Any]) -> pd.DataFrame:
"""
Pivot table v2.
"""
Expand Down
4 changes: 1 addition & 3 deletions superset/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def superset() -> None:
"""This is a management script for the Superset application."""

@app.shell_context_processor
def make_shell_context() -> Dict[str, Any]: # pylint: disable=unused-variable
def make_shell_context() -> Dict[str, Any]:
return dict(app=app, db=db)


Expand Down Expand Up @@ -297,7 +297,6 @@ def export_dashboards(dashboard_file: Optional[str] = None) -> None:
"the exception traceback in the log"
)

# pylint: disable=too-many-locals
@superset.command()
@with_appcontext
@click.option(
Expand Down Expand Up @@ -419,7 +418,6 @@ def export_dashboards(
with open(dashboard_file, "w") as data_stream:
data_stream.write(data)

# pylint: disable=too-many-locals
@superset.command()
@with_appcontext
@click.option(
Expand Down
1 change: 0 additions & 1 deletion superset/commands/importers/v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ def run(self) -> None:
db.session.rollback()
raise self.import_error() from ex

# pylint: disable=too-many-branches
def validate(self) -> None:
exceptions: List[ValidationError] = []

Expand Down
2 changes: 1 addition & 1 deletion superset/commands/importers/v1/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def _get_uuids(cls) -> Set[str]:
| ImportDashboardsCommand._get_uuids()
)

# pylint: disable=too-many-locals, arguments-differ, too-many-branches
# pylint: disable=too-many-locals, arguments-differ
@staticmethod
def _import(
session: Session,
Expand Down
5 changes: 2 additions & 3 deletions superset/common/query_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# pylint: disable=R
import logging
from datetime import datetime, timedelta
from typing import Any, Dict, List, NamedTuple, Optional
Expand Down Expand Up @@ -66,7 +65,7 @@ class DeprecatedField(NamedTuple):
)


class QueryObject:
class QueryObject: # pylint: disable=too-many-instance-attributes
"""
The query object's schema matches the interfaces of DB connectors like sqla
and druid. The query objects are constructed on the client.
Expand Down Expand Up @@ -99,7 +98,7 @@ class QueryObject:
is_rowcount: bool
time_offsets: List[str]

def __init__(
def __init__( # pylint: disable=too-many-arguments,too-many-locals
self,
datasource: Optional[DatasourceDict] = None,
result_type: Optional[ChartDataResultType] = None,
Expand Down
2 changes: 1 addition & 1 deletion superset/common/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def add_types(engine: Engine, metadata: Metadata) -> None:

# add a tag for each object type
insert = tag.insert()
for type_ in ObjectTypes.__members__: # pylint: disable=not-an-iterable
for type_ in ObjectTypes.__members__:
try:
engine.execute(insert, name=f"type:{type_}", type=TagTypes.type)
except IntegrityError:
Expand Down
21 changes: 7 additions & 14 deletions superset/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@
from flask_appbuilder.security.manager import AUTH_DB
from pandas.io.parsers import STR_NA_VALUES

from superset.jinja_context import ( # pylint: disable=unused-import
BaseTemplateProcessor,
)
from superset.jinja_context import BaseTemplateProcessor
from superset.stats_logger import DummyStatsLogger
from superset.typing import CacheConfig
from superset.utils.core import is_test, parse_boolean_string
Expand All @@ -51,12 +49,9 @@
logger = logging.getLogger(__name__)

if TYPE_CHECKING:
from flask_appbuilder.security.sqla import models # pylint: disable=unused-import

from superset.connectors.sqla.models import ( # pylint: disable=unused-import
SqlaTable,
)
from superset.models.core import Database # pylint: disable=unused-import
from flask_appbuilder.security.sqla import models
from superset.connectors.sqla.models import SqlaTable
from superset.models.core import Database

# Realtime stats logger, a StatsD implementation exists
STATS_LOGGER = DummyStatsLogger()
Expand Down Expand Up @@ -96,9 +91,7 @@ def _try_json_readversion(filepath: str) -> Optional[str]:
return None


def _try_json_readsha( # pylint: disable=unused-argument
filepath: str, length: int
) -> Optional[str]:
def _try_json_readsha(filepath: str, length: int) -> Optional[str]:
try:
with open(filepath, "r") as f:
return json.load(f).get("GIT_SHA")[:length]
Expand Down Expand Up @@ -928,7 +921,7 @@ def CSV_TO_HIVE_UPLOAD_DIRECTORY_FUNC(
HIVE_POLL_INTERVAL = int(timedelta(seconds=5).total_seconds())

# Interval between consecutive polls when using Presto Engine
# See here: https://github.com/dropbox/PyHive/blob/8eb0aeab8ca300f3024655419b93dad926c1a351/pyhive/presto.py#L93 # pylint: disable=line-too-long
# See here: https://github.com/dropbox/PyHive/blob/8eb0aeab8ca300f3024655419b93dad926c1a351/pyhive/presto.py#L93 # pylint: disable=line-too-long,useless-suppression
PRESTO_POLL_INTERVAL = int(timedelta(seconds=1).total_seconds())

# Allow for javascript controls components
Expand Down Expand Up @@ -1266,7 +1259,7 @@ def CSV_TO_HIVE_UPLOAD_DIRECTORY_FUNC(
elif importlib.util.find_spec("superset_config") and not is_test():
try:
import superset_config # pylint: disable=import-error
from superset_config import * # type: ignore # pylint: disable=import-error,wildcard-import,unused-wildcard-import
from superset_config import * # type: ignore # pylint: disable=import-error,wildcard-import

print(f"Loaded your LOCAL configuration at [{superset_config.__file__}]")
except Exception:
Expand Down
4 changes: 2 additions & 2 deletions superset/connectors/connector_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ def get_all_datasources(cls, session: Session) -> List["BaseDatasource"]:
return datasources

@classmethod
def get_datasource_by_id( # pylint: disable=too-many-arguments
cls, session: Session, datasource_id: int,
def get_datasource_by_id(
cls, session: Session, datasource_id: int
) -> "BaseDatasource":
"""
Find a datasource instance based on the unique id.
Expand Down
8 changes: 3 additions & 5 deletions superset/connectors/sqla/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import logging
import re
from collections import defaultdict, OrderedDict
from dataclasses import dataclass, field # pylint: disable=wrong-import-order
from dataclasses import dataclass, field
from datetime import datetime, timedelta
from typing import (
Any,
Expand Down Expand Up @@ -471,9 +471,7 @@ def data(self) -> Dict[str, Any]:
)


class SqlaTable( # pylint: disable=too-many-public-methods,too-many-instance-attributes
Model, BaseDatasource
):
class SqlaTable(Model, BaseDatasource): # pylint: disable=too-many-public-methods

"""An ORM object for SqlAlchemy table references"""

Expand Down Expand Up @@ -1290,7 +1288,7 @@ def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-ma
qry = qry.offset(row_offset)

if (
is_timeseries # pylint: disable=too-many-boolean-expressions
is_timeseries
and timeseries_limit
and not time_groupby_inline
and groupby_exprs_sans_timestamp
Expand Down
14 changes: 4 additions & 10 deletions superset/connectors/sqla/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@
logger = logging.getLogger(__name__)


class TableColumnInlineView( # pylint: disable=too-many-ancestors
CompactCRUDMixin, SupersetModelView
):
class TableColumnInlineView(CompactCRUDMixin, SupersetModelView):
datamodel = SQLAInterface(models.TableColumn)
# TODO TODO, review need for this on related_views
class_permission_name = "Dataset"
Expand Down Expand Up @@ -196,9 +194,7 @@ def pre_delete(self, item: "models.SqlMetric") -> None:
check_ownership(item.table)


class SqlMetricInlineView( # pylint: disable=too-many-ancestors
CompactCRUDMixin, SupersetModelView
):
class SqlMetricInlineView(CompactCRUDMixin, SupersetModelView):
datamodel = SQLAInterface(models.SqlMetric)
class_permission_name = "Dataset"
method_permission_name = MODEL_VIEW_RW_METHOD_PERMISSION_MAP
Expand Down Expand Up @@ -301,9 +297,7 @@ def __init__(self, **kwargs: Any):
super().__init__(**kwargs)


class RowLevelSecurityFiltersModelView( # pylint: disable=too-many-ancestors
SupersetModelView, DeleteMixin
):
class RowLevelSecurityFiltersModelView(SupersetModelView, DeleteMixin):
datamodel = SQLAInterface(models.RowLevelSecurityFilter)

list_widget = cast(SupersetListWidget, RowLevelSecurityListWidget)
Expand Down Expand Up @@ -561,7 +555,7 @@ def edit(self, pk: str) -> FlaskResponse:
@action(
"refresh", __("Refresh Metadata"), __("Refresh column metadata"), "fa-refresh"
)
def refresh( # pylint: disable=no-self-use, too-many-branches
def refresh( # pylint: disable=no-self-use,
self, tables: Union["TableModelView", List["TableModelView"]]
) -> FlaskResponse:
logger.warning(
Expand Down
6 changes: 3 additions & 3 deletions superset/dashboards/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def __repr__(self) -> str:
)

@etag_cache(
get_last_modified=lambda _self, id_or_slug: DashboardDAO.get_dashboard_changed_on( # pylint: disable=line-too-long
get_last_modified=lambda _self, id_or_slug: DashboardDAO.get_dashboard_changed_on( # pylint: disable=line-too-long,useless-suppression
id_or_slug
),
max_age=0,
Expand Down Expand Up @@ -279,7 +279,7 @@ def get(self, id_or_slug: str) -> Response:
return self.response_404()

@etag_cache(
get_last_modified=lambda _self, id_or_slug: DashboardDAO.get_dashboard_and_datasets_changed_on( # pylint: disable=line-too-long
get_last_modified=lambda _self, id_or_slug: DashboardDAO.get_dashboard_and_datasets_changed_on( # pylint: disable=line-too-long,useless-suppression
id_or_slug
),
max_age=0,
Expand Down Expand Up @@ -340,7 +340,7 @@ def get_datasets(self, id_or_slug: str) -> Response:
return self.response_404()

@etag_cache(
get_last_modified=lambda _self, id_or_slug: DashboardDAO.get_dashboard_and_slices_changed_on( # pylint: disable=line-too-long
get_last_modified=lambda _self, id_or_slug: DashboardDAO.get_dashboard_and_slices_changed_on( # pylint: disable=line-too-long,useless-suppression
id_or_slug
),
max_age=0,
Expand Down
1 change: 0 additions & 1 deletion superset/dashboards/commands/importers/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class ImportDashboardsCommand(BaseCommand):
until it finds one that matches.
"""

# pylint: disable=unused-argument
def __init__(self, contents: Dict[str, str], *args: Any, **kwargs: Any):
self.contents = contents
self.args = args
Expand Down
2 changes: 1 addition & 1 deletion superset/dashboards/commands/importers/v0.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def import_chart(


def import_dashboard(
# pylint: disable=too-many-locals,too-many-branches,too-many-statements
# pylint: disable=too-many-locals,too-many-statements
dashboard_to_import: Dashboard,
dataset_id_mapping: Optional[Dict[int, int]] = None,
import_time: Optional[int] = None,
Expand Down
2 changes: 0 additions & 2 deletions superset/dashboards/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,6 @@ def post_load(self, data: Dict[str, Any], **kwargs: Any) -> Dict[str, Any]:
data["slug"] = re.sub(r"[^\w\-]+", "", data["slug"])
return data

# pylint: disable=no-self-use,unused-argument


class DashboardPostSchema(BaseDashboardSchema):
dashboard_title = fields.String(
Expand Down
14 changes: 4 additions & 10 deletions superset/databases/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,7 @@ def post(self) -> Response:
action=lambda self, *args, **kwargs: f"{self.__class__.__name__}.put",
log_to_statsd=False,
)
def put( # pylint: disable=too-many-return-statements, arguments-differ
self, pk: int
) -> Response:
def put(self, pk: int) -> Response:
"""Changes a Database
---
put:
Expand Down Expand Up @@ -355,7 +353,7 @@ def put( # pylint: disable=too-many-return-statements, arguments-differ
action=lambda self, *args, **kwargs: f"{self.__class__.__name__}" f".delete",
log_to_statsd=False,
)
def delete(self, pk: int) -> Response: # pylint: disable=arguments-differ
def delete(self, pk: int) -> Response:
"""Deletes a Database
---
delete:
Expand Down Expand Up @@ -591,9 +589,7 @@ def select_star(
f".test_connection",
log_to_statsd=False,
)
def test_connection( # pylint: disable=too-many-return-statements
self,
) -> FlaskResponse:
def test_connection(self) -> FlaskResponse:
"""Tests a database connection
---
post:
Expand Down Expand Up @@ -977,9 +973,7 @@ def available(self) -> Response:
f".validate_parameters",
log_to_statsd=False,
)
def validate_parameters( # pylint: disable=too-many-return-statements
self,
) -> FlaskResponse:
def validate_parameters(self) -> FlaskResponse:
"""validates database connection parameters
---
post:
Expand Down
2 changes: 1 addition & 1 deletion superset/databases/commands/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def run(self) -> Model:
try:
# Test connection before starting create transaction
TestConnectionDatabaseCommand(self._actor, self._properties).run()
except Exception as ex: # pylint: disable=broad-except
except Exception as ex:
event_logger.log_with_context(
action=f"db_creation_failed.{ex.__class__.__name__}",
engine=self._properties.get("sqlalchemy_uri", "").split(":")[0],
Expand Down
1 change: 0 additions & 1 deletion superset/databases/commands/importers/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class ImportDatabasesCommand(BaseCommand):
until it finds one that matches.
"""

# pylint: disable=unused-argument
def __init__(self, contents: Dict[str, str], *args: Any, **kwargs: Any):
self.contents = contents
self.args = args
Expand Down
2 changes: 1 addition & 1 deletion superset/databases/commands/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def run(self) -> None:
engine=database.db_engine_spec.__name__,
)
raise DatabaseSecurityUnsafeError(message=str(ex)) from ex
except Exception as ex: # pylint: disable=broad-except
except Exception as ex:
event_logger.log_with_context(
action=f"test_connection_error.{ex.__class__.__name__}",
engine=database.db_engine_spec.__name__,
Expand Down
2 changes: 1 addition & 1 deletion superset/databases/commands/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def run(self) -> None:
try:
with closing(engine.raw_connection()) as conn:
alive = engine.dialect.do_ping(conn)
except Exception as ex: # pylint: disable=broad-except
except Exception as ex:
url = make_url(sqlalchemy_uri)
context = {
"hostname": url.host,
Expand Down
1 change: 0 additions & 1 deletion superset/datasets/commands/importers/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class ImportDatasetsCommand(BaseCommand):
until it finds one that matches.
"""

# pylint: disable=unused-argument
def __init__(self, contents: Dict[str, str], *args: Any, **kwargs: Any):
self.contents = contents
self.args = args
Expand Down
2 changes: 0 additions & 2 deletions superset/datasets/commands/importers/v1/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# pylint: disable=too-many-branches

import gzip
import json
import logging
Expand Down
Loading

0 comments on commit 7e4c940

Please sign in to comment.