Skip to content

Commit

Permalink
Fix some no-untyped-def errors (#305)
Browse files Browse the repository at this point in the history
  • Loading branch information
MCPN authored Feb 12, 2024
1 parent f853600 commit 11e9223
Show file tree
Hide file tree
Showing 64 changed files with 177 additions and 152 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class Job(Generic[_JOB_ITEM_TV], metaclass=abc.ABCMeta):
_worker_thread_started_event = attr.ib(init=False, factory=asyncio.Event)
_log: logging.LoggerAdapter = attr.ib(init=False, default=None)

def __attrs_post_init__(self): # type: ignore # TODO: fix
def __attrs_post_init__(self) -> None:
self._log = logging.LoggerAdapter(
logging.getLogger(__name__),
extra=dict(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class BIAioHTTPClient:
_ca_data: bytes = attr.ib()
_session: Optional[aiohttp.ClientSession] = attr.ib(init=False)

def __attrs_post_init__(self): # type: ignore # 2024-01-24 # TODO: Function is missing a return type annotation [no-untyped-def]
def __attrs_post_init__(self) -> None:
self._session = self._make_session()

def _make_session(self) -> aiohttp.ClientSession:
Expand Down
7 changes: 6 additions & 1 deletion lib/dl_api_lib/dl_api_lib/api_common/dataset_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from copy import deepcopy
import logging
from typing import (
TYPE_CHECKING,
NamedTuple,
Optional,
)
Expand Down Expand Up @@ -38,6 +39,10 @@
from dl_utils.aio import await_sync


if TYPE_CHECKING:
from dl_core.rls import RLSEntry


LOGGER = logging.getLogger(__name__)


Expand Down Expand Up @@ -254,7 +259,7 @@ def _update_dataset_source_avatar_relations_from_body(cls, dataset: Dataset, bod
return handled_avatar_relation_ids

@staticmethod
def _rls_list_to_set(rls_list): # type: ignore # TODO: fix
def _rls_list_to_set(rls_list: list[RLSEntry]) -> set[tuple]:
return set(
(
rlse.field_guid,
Expand Down
2 changes: 1 addition & 1 deletion lib/dl_api_lib/dl_api_lib/dataset/base_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def _reload_formalized_specs(self, block_spec: Optional[BlockSpec] = None) -> No
def allow_nested_window_functions(self) -> bool:
return True

def load_exbuilders(self): # type: ignore # TODO: fix
def load_exbuilders(self) -> None:
self.inspect_env = InspectionEnvironment()
self._column_reg = ColumnRegistry(
db_columns=self._generate_raw_column_list(),
Expand Down
2 changes: 1 addition & 1 deletion lib/dl_api_lib/dl_api_lib/public/entity_usage_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def ensure_dataset_can_be_used(
else:
raise EntityUsageNotAllowed(f"Unexpected data source role resolved for dataset {dataset.uuid}")

def ensure_data_connection_can_be_used(self, rci: RequestContextInfo, conn: ConnectionBase): # type: ignore # TODO: fix
def ensure_data_connection_can_be_used(self, rci: RequestContextInfo, conn: ConnectionBase) -> None:
LOGGER.info("Checking if connection %s %s can be used in public env", conn.conn_type, conn.uuid)
if conn.allow_public_usage:
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@

if TYPE_CHECKING:
from dl_core.services_registry.top_level import ServicesRegistry
from dl_core.us_entry import USEntry
from dl_query_processing.compilation.query_meta import QueryMetaInfo
from dl_query_processing.legend.block_legend import BlockSpec

Expand All @@ -86,7 +87,7 @@
}


def need_permission_on_entry(us_entry, permission) -> None: # type: ignore # 2024-01-30 # TODO: Function is missing a type annotation for one or more arguments [no-untyped-def]
def need_permission_on_entry(us_entry: USEntry, permission: str) -> None:
# TODO: DELETE ME after the check is moved up the stack
assert us_entry.permissions is not None
assert us_entry.uuid is not None
Expand Down
4 changes: 2 additions & 2 deletions lib/dl_api_lib/dl_api_lib/query/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@ def register_compeng_dialect(dialect: DialectCombo) -> None:
_IS_FORKABLE_DEFAULT = True


def is_forkable_dialect(dialect: DialectCombo): # type: ignore # 2024-01-24 # TODO: Function is missing a return type annotation [no-untyped-def]
def is_forkable_dialect(dialect: DialectCombo) -> bool:
return _IS_FORKABLE_DIALECT.get(dialect.common_name, _IS_FORKABLE_DEFAULT)


def register_forkable_dialect_name(dialect_name: DialectName, is_forkable: bool): # type: ignore # 2024-01-24 # TODO: Function is missing a return type annotation [no-untyped-def]
def register_forkable_dialect_name(dialect_name: DialectName, is_forkable: bool) -> None:
try:
assert _IS_FORKABLE_DIALECT[dialect_name] is is_forkable
except KeyError:
Expand Down
2 changes: 1 addition & 1 deletion lib/dl_api_lib_testing/dl_api_lib_testing/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class ApiTestBase(abc.ABC):
query_processing_mode: ClassVar[QueryProcessingMode] = QueryProcessingMode.basic

@pytest.fixture(scope="function", autouse=True)
def preload(self): # type: ignore # 2024-01-29 # TODO: Function is missing a return type annotation [no-untyped-def]
def preload(self) -> None:
preload_api_lib()

@pytest.fixture(scope="class")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,13 +479,13 @@ def test_basic_preview(
class DefaultConnectorDataCacheTestSuite(StandardizedDataApiTestBase, RegulatedTestCase):
data_caches_enabled = True

def test_cache_with_filter_with_constants( # type: ignore # 2024-01-29 # TODO: Function is missing a return type annotation [no-untyped-def]
def test_cache_with_filter_with_constants(
self,
control_api: SyncHttpDatasetApiV1,
data_api: SyncHttpDataApiV2,
db: Db,
saved_connection_id: str,
):
) -> None:
"""
There used to problems with the generation of cache keys for MySQL.
This test makes sure that cache keys for queries with different and repeated constants
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,6 @@ def get_or_create_schema_bundle_for_attrs_class(self, target: Type) -> SchemaBun
if target in self._map_complex_type_schema_bundle:
return self._map_complex_type_schema_bundle[target]

# TODO FIX: Determine why MyPy thinks "error: Module has no attribute "resolve_types"
attr.resolve_types(target)
schema_bundle: SchemaBundle

Expand Down
7 changes: 5 additions & 2 deletions lib/dl_compeng_pg/dl_compeng_pg/compeng_aiopg/pool_aiopg.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ def pool(self) -> aiopg.sa.Engine:
return self._pool

async def disconnect(self) -> None:
if self._pool is None:
raise RuntimeError("Aiopg pool is closed")

pool = self._pool
self._pool = None
pool.terminate() # type: ignore # TODO: fix
await pool.wait_closed() # type: ignore # TODO: fix
pool.terminate()
await pool.wait_closed()
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ async def finalize(self) -> None:
await self._deinit_pool()

async def _deinit_pool(self) -> None:
"""..."""
assert self._pool is not None
LOGGER.info("Tear down compeng pg pool %r...", self)
await self._pool.disconnect() # type: ignore # TODO: fix
await self._pool.disconnect()
self._pool = None
LOGGER.info("Tear down compeng pg pool %r: done.", self)

Expand Down
4 changes: 2 additions & 2 deletions lib/dl_configs/dl_configs/crypto_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ class CryptoKeysConfig(SettingsBase):
actual_key_id: str = s_attrib("ACTUAL_KEY_ID") # type: ignore # 2024-01-24 # TODO: Incompatible types in assignment (expression has type "Attribute[Any]", variable has type "str") [assignment]

@actual_key_id.default # type: ignore # 2024-01-24 # TODO: "str" has no attribute "default" [attr-defined]
def _default_actual_key_id(self): # type: ignore # 2024-01-24 # TODO: Function is missing a return type annotation [no-untyped-def]
def _default_actual_key_id(self) -> str:
if len(self.map_id_key) == 1:
return next(iter(self.map_id_key.keys()))
# TODO FIX: Integrate with env loader exceptions handling
raise ValueError("Missing actual_key_id (acceptable only in single key case)")

def __attrs_post_init__(self): # type: ignore # 2024-01-24 # TODO: Function is missing a return type annotation [no-untyped-def]
def __attrs_post_init__(self) -> None:
if self.actual_key_id not in self.map_id_key:
raise ValueError()

Expand Down
4 changes: 1 addition & 3 deletions lib/dl_configs/dl_configs/environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
"""
from __future__ import annotations

from typing import Any


def is_setting_applicable(cfg: object, key: str): # type: ignore # 2024-01-24 # TODO: Function is missing a return type annotation [no-untyped-def]
def is_setting_applicable(cfg: object, key: str) -> bool:
# TODO: remove it
# it's a crutch-function
# we will remove this after migrating values to dedicated keys
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __len__(self) -> int:
def __iter__(self) -> Iterator:
return iter(self._data)

def _get_key(self, key: Any): # type: ignore # 2024-01-24 # TODO: Function is missing a return type annotation [no-untyped-def]
def _get_key(self, key: Any) -> Any:
if key not in self._data:
path = ".".join(self._path + [key])
raise AttributeError(f'There is no record in config by path: "{path}"')
Expand Down Expand Up @@ -91,7 +91,7 @@ def _get_config_path(cls, s_dict: SDict) -> Optional[str]:
return path

@classmethod
def is_config_enabled(cls, s_dict: SDict): # type: ignore # 2024-01-24 # TODO: Function is missing a return type annotation [no-untyped-def]
def is_config_enabled(cls, s_dict: SDict) -> bool:
result = cls._get_config_path(s_dict) is not None
LOGGER.info('Check path key in s_dict: "%s"', result)
return result
Expand Down
8 changes: 4 additions & 4 deletions lib/dl_configs/dl_configs/settings_loaders/loader_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def field_set(self) -> set[str]:
return self._field_set


def get_sub_keys(prefix: str, env: SDict): # type: ignore # 2024-01-24 # TODO: Function is missing a return type annotation [no-untyped-def]
def get_sub_keys(prefix: str, env: SDict) -> dict[str, str]:
effective_prefix = prefix if prefix.endswith(SEP) else prefix + SEP
return {key[len(effective_prefix) :]: value for key, value in env.items() if key.startswith(effective_prefix)}

Expand Down Expand Up @@ -132,7 +132,7 @@ def _extract(self, s_dict: SDict) -> Any:

@attr.s
class DefaultOnlyExtractor(SDictExtractor):
def __attrs_post_init__(self): # type: ignore # 2024-01-24 # TODO: Function is missing a return type annotation [no-untyped-def]
def __attrs_post_init__(self) -> None:
assert self.default is not NOT_SET

def has_field(self, s_dict: SDict) -> bool:
Expand Down Expand Up @@ -210,7 +210,7 @@ def _ensure_no_missing_fields(
missing_required_fields: list[attr.Attribute] = []
missing_sub_field_code_set: set[str] = set()

def handle_field_sub_exc(faulty_field_name: str, exc: ConfigFieldMissing): # type: ignore # 2024-01-24 # TODO: Function is missing a return type annotation [no-untyped-def]
def handle_field_sub_exc(faulty_field_name: str, exc: ConfigFieldMissing) -> None:
missing_sub_field_code_set.update(f"{faulty_field_name}.{sub_field}" for sub_field in exc.field_set)

if obj is None:
Expand Down Expand Up @@ -308,7 +308,7 @@ class EnvSettingsLoader:

_s_dict: Optional[SDict] = attr.ib(repr=False)

def __attrs_post_init__(self): # type: ignore # 2024-01-24 # TODO: Function is missing a return type annotation [no-untyped-def]
def __attrs_post_init__(self) -> None:
if self._s_dict is None:
self._s_dict = MappingProxyType(dict(os.environ))
else:
Expand Down
4 changes: 2 additions & 2 deletions lib/dl_configs/dl_configs/settings_loaders/meta_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ class SMeta:
enabled_key_name: Optional[str] = attr.ib(default=None)
is_app_cfg_type: bool = attr.ib(default=False)

def __attrs_post_init__(self): # type: ignore # 2024-01-24 # TODO: Function is missing a return type annotation [no-untyped-def]
def __attrs_post_init__(self) -> None:
assert not (
self.fallback_cfg_key is not None and self.fallback_factory is not None
), "fallback_factory and fallback_cfg_key can not be defined together"

def to_dict(self): # type: ignore # 2024-01-24 # TODO: Function is missing a return type annotation [no-untyped-def]
def to_dict(self) -> dict[str, SMeta]:
return {self.attrs_meta_key: self}

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion lib/dl_constants/dl_constants/exc.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def __str__(self) -> str:
# ##
_MAP_CLASS_NAME_CLASS: ClassVar[dict[str, Type["DLBaseException"]]] = {}

def __init_subclass__(cls, **kwargs): # type: ignore # 2024-01-30 # TODO: Function is missing a type annotation [no-untyped-def]
def __init_subclass__(cls, **kwargs: Any) -> None:
cls._MAP_CLASS_NAME_CLASS[cls.__qualname__] = cls

@classmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class DLExcSchema(Schema):
dl_exec_dict = fields.Function(serialize=lambda exc: exc.to_jsonable_dict(), deserialize=lambda o: o)

@post_load(pass_many=False)
def post_load(self, data: dict, **_) -> DLBaseException: # type: ignore # 2024-01-30 # TODO: Function is missing a type annotation for one or more arguments [no-untyped-def]
def post_load(self, data: dict, **_: Any) -> DLBaseException:
return DLBaseException.from_jsonable_dict(data["dl_exec_dict"])


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class SourceDbExecAdapter(ProcessorDbExecAdapterBase): # noqa
_row_count_hard_limit: Optional[int] = attr.ib(kw_only=True, default=None)
_us_entry_buffer: USEntryBuffer = attr.ib(kw_only=True)

def __attrs_post_init__(self): # type: ignore # TODO: fix
def __attrs_post_init__(self) -> None:
if self._prep_component_manager is None:
self._prep_component_manager = DefaultPreparedComponentManager(
dataset=self._dataset,
Expand Down
2 changes: 1 addition & 1 deletion lib/dl_core/dl_core/data_source/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def _validate_connection(self) -> None:
if self._connection is not None:
self._validate_connection_cls(self._connection)

def __attrs_post_init__(self): # type: ignore # TODO: fix
def __attrs_post_init__(self) -> None:
self._validate_connection()

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion lib/dl_core/dl_core/dataset_capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def get_compatible_source_types(source_type: DataSourceType) -> FrozenSet[DataSo
_SOURCE_CONNECTION_COMPATIBILITY: Dict[DataSourceType, FrozenSet[ConnectionType]] = {}


def _populate_compatibility_map(): # type: ignore # TODO: fix
def _populate_compatibility_map() -> None:
for conn_type, conn_cls in CONNECTION_TYPES.items():
for dsrc_type in conn_cls.get_provided_source_types():
_SOURCE_CONNECTION_COMPATIBILITY[dsrc_type] = _SOURCE_CONNECTION_COMPATIBILITY.get(
Expand Down
2 changes: 1 addition & 1 deletion lib/dl_core/dl_core/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ class ResultSchema:
_title_cache: Dict[str, BIField] = attr.ib(init=False, eq=False)
valid: bool = attr.ib(default=True)

def __attrs_post_init__(self): # type: ignore # TODO: fix
def __attrs_post_init__(self) -> None:
self._guid_cache = {}
self._title_cache = {}
self.reload_caches()
Expand Down
2 changes: 1 addition & 1 deletion lib/dl_core/dl_core/raw_data_streaming/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class DataStreamBase(Iterator[_ITER_TV], metaclass=ABCMeta):
max_percent = 99

def __iter__(self): # type: ignore # TODO: fix
def __iter__(self) -> DataStreamBase:
return self

def get_progress_percent(self) -> int:
Expand Down
2 changes: 1 addition & 1 deletion lib/dl_core/dl_core/us_manager/broken_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class BrokenUSLink:
reference: ConnectionRef = attr.ib()
_referrer_id_set: set[str] = attr.ib(init=False, factory=set)

def __attrs_post_init__(self): # type: ignore # TODO: fix
def __attrs_post_init__(self) -> None:
self._referrer_id_set = set(self._referrer_id_set)

@property
Expand Down
2 changes: 1 addition & 1 deletion lib/dl_core/dl_core/us_manager/crypto/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class CryptoController:
_key_config: CryptoKeysConfig = attr.ib()
_map_key_id_fernet_instance: typing.Dict[str, fernet.Fernet] = attr.ib(init=False)

def __attrs_post_init__(self): # type: ignore # TODO: fix
def __attrs_post_init__(self) -> None:
self._map_key_id_fernet_instance = {
key_id: fernet.Fernet(key_val) for key_id, key_val in self._key_config.map_id_key.items()
}
Expand Down
4 changes: 2 additions & 2 deletions lib/dl_core/dl_core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def parse_comma_separated_hosts(host: Optional[str]) -> tuple[str, ...]:
return tuple(h.strip() for h in host.split(","))


def validate_hostname_or_ip_address(hostname: str): # type: ignore # TODO: fix
def validate_hostname_or_ip_address(hostname: str) -> None:
# IP address case
try:
ipaddress.ip_address(hostname)
Expand Down Expand Up @@ -149,7 +149,7 @@ def validate_hostname_or_ip_address(hostname: str): # type: ignore # TODO: fix
raise ValueError("Not a valid netloc")


def shorten_uuid(some_uuid: str): # type: ignore # TODO: fix
def shorten_uuid(some_uuid: str) -> str:
return shortuuid.encode(uuid.UUID(some_uuid))


Expand Down
4 changes: 2 additions & 2 deletions lib/dl_core_testing/dl_core_testing/testcases/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ def _make_dba(self, target_dto: _TARGET_DTO_TV, rci: RequestContextInfo) -> Asyn
default_chunk_size=10,
)

async def _test_pass_db_query_to_user( # type: ignore # 2024-01-29 # TODO: Function is missing a return type annotation [no-untyped-def]
async def _test_pass_db_query_to_user(
self,
pass_db_query_to_user: Optional[bool],
query_to_send: str,
expected_query: Optional[str],
conn_bi_context: RequestContextInfo,
target_conn_dto: _TARGET_DTO_TV,
):
) -> None:
debug_query = expected_query

target_conn_dto = target_conn_dto.clone(port="65535") # not the actual db port to raise connect error
Expand Down
Loading

0 comments on commit 11e9223

Please sign in to comment.