Skip to content

Commit

Permalink
chore: Remove some redundant calls to typing.cast (meltano#2077)
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon authored Nov 29, 2023
1 parent a2cdfe8 commit 34027f9
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 14 deletions.
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,10 @@ fail_under = 82
exclude = "tests"
files = "singer_sdk"
python_version = "3.8"
warn_redundant_casts = true
warn_return_any = true
warn_unused_configs = true
warn_unused_ignores = true
warn_return_any = true

[[tool.mypy.overrides]]
ignore_missing_imports = true
Expand Down
5 changes: 1 addition & 4 deletions singer_sdk/about.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,7 @@ def format_about(self, about_info: AboutInfo) -> str:
Returns:
A formatted string.
"""
max_setting_len = t.cast(
int,
max(len(k) for k in about_info.settings["properties"]),
)
max_setting_len = max(len(k) for k in about_info.settings["properties"])

# Set table base for markdown
table_base = (
Expand Down
11 changes: 4 additions & 7 deletions singer_sdk/connectors/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@

import simplejson
import sqlalchemy
from sqlalchemy.engine import Engine

from singer_sdk import typing as th
from singer_sdk._singerlib import CatalogEntry, MetadataMapping, Schema
from singer_sdk.exceptions import ConfigValidationError
from singer_sdk.helpers.capabilities import TargetLoadMethods

if t.TYPE_CHECKING:
from sqlalchemy.engine import Engine
from sqlalchemy.engine.reflection import Inspector


Expand Down Expand Up @@ -293,7 +293,7 @@ def _dialect(self) -> sqlalchemy.engine.Dialect:
Returns:
The dialect object.
"""
return t.cast(sqlalchemy.engine.Dialect, self._engine.dialect)
return self._engine.dialect

@property
def _engine(self) -> Engine:
Expand All @@ -307,7 +307,7 @@ def _engine(self) -> Engine:
"""
if not self._cached_engine:
self._cached_engine = self.create_engine()
return t.cast(Engine, self._cached_engine)
return self._cached_engine

def create_engine(self) -> Engine:
"""Creates and returns a new engine. Do not call outside of _engine.
Expand Down Expand Up @@ -572,10 +572,7 @@ def table_exists(self, full_table_name: str) -> bool:
"""
_, schema_name, table_name = self.parse_full_table_name(full_table_name)

return t.cast(
bool,
sqlalchemy.inspect(self._engine).has_table(table_name, schema_name),
)
return sqlalchemy.inspect(self._engine).has_table(table_name, schema_name)

def schema_exists(self, schema_name: str) -> bool:
"""Determine if the target database schema already exists.
Expand Down
2 changes: 1 addition & 1 deletion singer_sdk/helpers/_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def _find_in_partitions_list(
f"{{state_partition_context}}.\nMatching state values were: {found!s}"
)
raise ValueError(msg)
return t.cast(dict, found[0]) if found else None
return found[0] if found else None


def _create_in_partitions_list(
Expand Down
2 changes: 1 addition & 1 deletion singer_sdk/streams/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def _singer_catalog_entry(self) -> CatalogEntry:
Returns:
A CatalogEntry object.
"""
return t.cast(CatalogEntry, CatalogEntry.from_dict(self.catalog_entry))
return CatalogEntry.from_dict(self.catalog_entry)

@property
def connector(self) -> SQLConnector:
Expand Down

0 comments on commit 34027f9

Please sign in to comment.