Skip to content

Commit

Permalink
Warn unused ignores (#78)
Browse files Browse the repository at this point in the history
* deps: add pymongo for dev

* deps: switch from appdirs to platformdirs

* mypy: remove unused ignores

* mypy: ignore specific errors

* Bump version to 0.10.2a0
  • Loading branch information
jvansanten authored Jun 5, 2024
1 parent aeb3525 commit 0fcf599
Show file tree
Hide file tree
Showing 17 changed files with 154 additions and 34 deletions.
2 changes: 1 addition & 1 deletion ampel/alert/AmpelAlert.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
'is': operator.is_,
'is not': operator.is_not,
'contains': operator.contains,
'exists': None, # type: ignore
'exists': None, # type: ignore[dict-item]
}


Expand Down
6 changes: 3 additions & 3 deletions ampel/base/AlternativeAmpelBaseModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def __init_subclass__(cls, *args, **kwargs) -> None:
Combines annotations & default values of this class with the one defined in sub-classes.
Has similarities with the newly introduced typing.get_type_hints() function.
"""
super().__init_subclass__(*args, **kwargs) # type: ignore
super().__init_subclass__(*args, **kwargs)

joined_ann = {
k: v for k, v in cls._annots.items()
Expand All @@ -78,7 +78,7 @@ def __init_subclass__(cls, *args, **kwargs) -> None:
continue
joined_defaults[k] = base.__dict__[k]
# if None | with no default
elif get_origin(v) in (Union, UnionType) and NoneType in get_args(v) and k not in joined_defaults: # type: ignore[misc]
elif get_origin(v) in (Union, UnionType) and NoneType in get_args(v) and k not in joined_defaults:
joined_defaults[k] = None
elif k in cls._slot_defaults:
joined_defaults[k] = cls._slot_defaults[k]
Expand Down Expand Up @@ -164,7 +164,7 @@ def _has_nested_model(cls, annot: type) -> bool:
if cls._debug > 1:
print("Checking " + str(annot).replace('collections.abc.', '') + " for nested models")

if isinstance(annot, _GenericAlias) and hasattr(annot, 'mro') and issubclass(get_origin(annot), Secret): # type: ignore
if isinstance(annot, _GenericAlias) and hasattr(annot, 'mro') and issubclass(get_origin(annot), Secret):
return True

for i, el in enumerate(get_args(annot)):
Expand Down
3 changes: 1 addition & 2 deletions ampel/base/AmpelABC.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ def __init_subclass__(cls, abstract: bool = False, **kwargs) -> None:
omits to call to the super method.
"""

# https://github.com/python/mypy/issues/5887
super().__init_subclass__(**kwargs) # type: ignore
super().__init_subclass__(**kwargs)

# If class name contains '[', it is parameterization of a subclass of
# (AmpelBaseModel, Generic), and not a true subclass. Skip it.
Expand Down
8 changes: 4 additions & 4 deletions ampel/base/AmpelUnit.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __init_subclass__(cls, *args, **kwargs) -> None:
Combines annotations & default values of this class with the one defined in sub-classes.
Has similarities with the newly introduced typing.get_type_hints() function.
"""
super().__init_subclass__(*args, **kwargs) # type: ignore
super().__init_subclass__(*args, **kwargs)

joined_ann = {
k: v for k, v in cls._annots.items()
Expand Down Expand Up @@ -89,7 +89,7 @@ def __init_subclass__(cls, *args, **kwargs) -> None:
else:
joined_defaults[k] = base.__dict__[k]
# if None | with no default
elif get_origin(v) in (Union, UnionType) and NoneType in get_args(v) and k not in joined_defaults: # type: ignore[misc]
elif get_origin(v) in (Union, UnionType) and NoneType in get_args(v) and k not in joined_defaults:
joined_defaults[k] = None
elif k in cls._slot_defaults:
joined_defaults[k] = cls._slot_defaults[k]
Expand Down Expand Up @@ -123,7 +123,7 @@ def _create_model(cls, omit_traceless: bool = False) -> type[BaseModel]:

defs = cls._defaults
if hasattr(cls, 'model_fields'):
cls.model_fields.clear() # type: ignore[attr-defined]
cls.model_fields.clear()

if omit_traceless:
ttf = type(Traceless)
Expand All @@ -141,7 +141,7 @@ def _create_model(cls, omit_traceless: bool = False) -> type[BaseModel]:
return create_model(
cls.__name__,
__base__ = AmpelBaseModel,
**kwargs # type: ignore
**kwargs # type: ignore[call-overload]
)


Expand Down
8 changes: 4 additions & 4 deletions ampel/base/AuxUnitRegister.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# Last Modified By: valery brinnel <firstname.lastname@gmail.com>

from importlib import import_module
from typing import Any, ClassVar, overload # type: ignore[attr-defined]
from typing import Any, ClassVar, overload

from ampel.base.AmpelUnit import AmpelUnit
from ampel.config.AmpelConfig import AmpelConfig
Expand Down Expand Up @@ -51,12 +51,12 @@ def new_unit(cls, model: UnitModel, *, sub_type: None | type[T] = None, **kwargs

if model.config:
if isinstance(model.config, dict):
return Klass(**(model.config | kwargs)) # type: ignore[call-arg]
return Klass(**(model.config | kwargs))
raise ValueError("Auxiliary units cannot use config aliases")

unit = Klass(**kwargs) # type: ignore[call-arg]
unit = Klass(**kwargs)
if hasattr(unit, "post_init"):
unit.post_init() # type: ignore[union-attr]
unit.post_init()

return unit

Expand Down
2 changes: 1 addition & 1 deletion ampel/base/LogicalUnit.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class LogicalUnit(AmpelUnit):

@classmethod
def __init_subclass__(cls, **kwargs) -> None:
super().__init_subclass__(**kwargs) # type: ignore
super().__init_subclass__(**kwargs)
cls.require = tuple(
set(getattr(cls, "require", None) or []) | {
el for base in cls.__bases__
Expand Down
3 changes: 2 additions & 1 deletion ampel/cli/AmpelArgumentParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ def __init__(self, ampel_op: None | str = None, **kwargs) -> None:
optional_group._group_actions = []

# Capitalize title
optional_group.title = optional_group.title.capitalize() # type: ignore
if optional_group.title:
optional_group.title = optional_group.title.capitalize()

# Add required argument group (first pos)
self.groups["required"] = self.add_argument_group('Required arguments')
Expand Down
2 changes: 1 addition & 1 deletion ampel/cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from os import environ, makedirs, path

from appdirs import user_data_dir # type: ignore[import]
from platformdirs import user_data_dir


def get_user_data_config_path() -> str:
Expand Down
2 changes: 1 addition & 1 deletion ampel/config/AmpelConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def get(self, entry: str | int | Sequence[str | int], ret_type: type[JT], *, rai
""" config.get('logging', dict, raise_exc=True) """


def get(self, # type: ignore[misc]
def get(self,
entry: None | str | int | Sequence[str | int] = None,
ret_type: None | type[JT] = None,
*, raise_exc: bool = False
Expand Down
4 changes: 2 additions & 2 deletions ampel/util/hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# Last Modified Date: 12.07.2022
# Last Modified By: valery brinnel <firstname.lastname@gmail.com>

import json # type: ignore[import]
import json
from typing import TypeVar

import xxhash
Expand Down Expand Up @@ -48,7 +48,7 @@ def hash_payload(payload: bytes, ret: type[HT] = int, size: int = -64) -> HT: #
x = getattr(xxhash, f'xxh{abs(size)}_{xxfunc[ret]}')(payload)

# Convert unsigned to signed int if passed 'size' parameter is negative
if size < 0 and ret == int and x & (1 << (-size-1)): # type: ignore[operator]
if size < 0 and ret == int and x & (1 << (-size-1)):
x = x - 2**-size

return x
Expand Down
4 changes: 2 additions & 2 deletions ampel/util/mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def set_by_path(
:returns: False if the key was successfully set, True otherwise
"""
if isinstance(path, str):
path = path.split(delimiter) # type: ignore
path = path.split(delimiter)
l = len(path) - 1
for i, k in enumerate(path):
if k not in d:
Expand All @@ -121,7 +121,7 @@ def del_by_path(d: dict, path: str | Sequence[str], delimiter: str = '.') -> boo
""" :returns: False if the key was successfully deleted, True otherwise """

if isinstance(path, str):
path = path.split(delimiter) # type: ignore
path = path.split(delimiter)
l = len(path) - 1
for i, k in enumerate(path):
if k not in d:
Expand Down
2 changes: 1 addition & 1 deletion ampel/util/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def merge_tags(
if arg1 is None:
if arg2 is None:
return None
return merge_tags(arg2, arg1, reduce) # type: ignore # no idea, no time
return merge_tags(arg2, arg1, reduce) # type: ignore[call-overload] # no idea, no time

if isinstance(arg1, str | int):
if isinstance(arg2, str | int):
Expand Down
6 changes: 3 additions & 3 deletions ampel/view/ReadOnlyDict.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ def __readonly__(self, *args, **kwargs):

__setitem__ = __readonly__
__delitem__ = __readonly__
pop = __readonly__ # type: ignore
pop = __readonly__ # type: ignore[assignment]
popitem = __readonly__
clear = __readonly__
update = __readonly__ # type: ignore
setdefault = __readonly__ # type: ignore
update = __readonly__ # type: ignore[assignment]
setdefault = __readonly__ # type: ignore[assignment]

del __readonly__

Expand Down
2 changes: 1 addition & 1 deletion ampel/view/SnapView.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def get_t2_ntuple(self,
"""

for t2v in self.get_t2_views(unit):
if (x := t2v.get_ntuple( # type: ignore
if (x := t2v.get_ntuple( # type: ignore[call-overload]
key, rtype, no_none = no_none, require_all_keys = require_all_keys, code = code
)):
return x
Expand Down
2 changes: 1 addition & 1 deletion ampel/view/T2DocView.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def get_ntuple(self,
for k in key
)

return None if (no_none and None in t) else t # type: ignore[return-value]
return None if (no_none and None in t) else t

return None

Expand Down
Loading

0 comments on commit 0fcf599

Please sign in to comment.