Skip to content

Commit

Permalink
Adjust the names of some type variables to recent pylint changes (see p…
Browse files Browse the repository at this point in the history
  • Loading branch information
tyralla committed Apr 1, 2022
1 parent 0fb8c13 commit 25c62ce
Show file tree
Hide file tree
Showing 13 changed files with 228 additions and 240 deletions.
2 changes: 1 addition & 1 deletion hydpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@
"start_server",
]

sequence2alias: Dict[sequencetools.TypesInOutSequence, str] = {}
sequence2alias: Dict[sequencetools.InOutSequenceTypes, str] = {}

if config.USEAUTODOC:
with warnings.catch_warnings():
Expand Down
8 changes: 4 additions & 4 deletions hydpy/auxs/anntools.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

class _ANNArrayProperty(
propertytools.DependentProperty[
propertytools.InputType,
propertytools.OutputType,
propertytools.TypeInput,
propertytools.TypeOutput,
],
):

Expand Down Expand Up @@ -53,11 +53,11 @@ def add_cann(cls, obj: Any, cann: annutils.ANN) -> None:
def _shape(self) -> str:
return f"shape_{self.name}"

def _fget(self, obj: "ANN") -> propertytools.OutputType:
def _fget(self, obj: "ANN") -> propertytools.TypeOutput:
cann = self._obj2cann[obj]
return numpy.asarray(getattr(cann, self.name))

def _fset(self, obj: "ANN", value: Optional[propertytools.InputType]) -> None:
def _fset(self, obj: "ANN", value: Optional[propertytools.TypeInput]) -> None:
if value is None:
self.fdel(obj)
else:
Expand Down
64 changes: 32 additions & 32 deletions hydpy/auxs/calibtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@
from hydpy.models.arma import arma_control
from hydpy.core.typingtools import *

ParameterType = TypeVar("ParameterType", bound=parametertools.Parameter)
RuleType1 = TypeVar(
"RuleType1",
TypeParameter = TypeVar("TypeParameter", bound=parametertools.Parameter)
TypeRule1 = TypeVar(
"TypeRule1",
bound=Union["Replace", "Add", "Multiply", "ReplaceIUH", "MultiplyIUH"],
)
RuleType2 = TypeVar(
"RuleType2",
TypeRule2 = TypeVar(
"TypeRule2",
bound=Union["Replace", "Add", "Multiply", "ReplaceIUH", "MultiplyIUH"],
)
RuleType = TypeVar("RuleType", "Replace", "Add", "Multiply")
TypeRule = TypeVar("TypeRule", "Replace", "Add", "Multiply")
Target = Optional[str]


Expand Down Expand Up @@ -298,7 +298,7 @@ def __call__(
target.value = self._rule.value * ref.value


class Rule(abc.ABC, Generic[ParameterType]):
class Rule(abc.ABC, Generic[TypeParameter]):
"""Base class for defining calibration rules.
Each |Rule| object relates one calibration parameter with some model parameters.
Expand Down Expand Up @@ -532,7 +532,7 @@ class Rule(abc.ABC, Generic[ParameterType]):
parametername: str
"""The name of the addressed |Parameter| objects."""

parametertype: Type[ParameterType]
parametertype: Type[TypeParameter]
"""The type of the addressed |Parameter| objects."""

keyword: Optional[str]
Expand All @@ -554,7 +554,7 @@ def __init__(
self,
*,
name: str,
parameter: Union[Type[ParameterType], ParameterType, str],
parameter: Union[Type[TypeParameter], TypeParameter, str],
value: float,
lower: float = -numpy.inf,
upper: float = numpy.inf,
Expand Down Expand Up @@ -785,7 +785,7 @@ def __repr__(self) -> str:
def __str__(self) -> str:
return self.name

def __iter__(self) -> Iterator[ParameterType]:
def __iter__(self) -> Iterator[TypeParameter]:
for element in self.elements:
yield getattr(
element.model.parameters.control,
Expand Down Expand Up @@ -1007,7 +1007,7 @@ def apply_value(self) -> None:
self._update_parameter(parameter, self.value * orig)


class CalibrationInterface(Generic[RuleType1]):
class CalibrationInterface(Generic[TypeRule1]):
"""Interface for the coupling of *HydPy* to optimisation libraries like `NLopt`_.
Essentially, class |CalibrationInterface| is supposed for the structured handling
Expand Down Expand Up @@ -1482,7 +1482,7 @@ class CalibrationInterface(Generic[RuleType1]):
_logfilelines: Deque[str]
_hp: hydpytools.HydPy
_targetfunction: TargetFunction
_rules: Dict[str, RuleType1]
_rules: Dict[str, TypeRule1]
_elements: devicetools.Elements

def __init__(self, hp: hydpytools.HydPy, targetfunction: TargetFunction):
Expand All @@ -1495,7 +1495,7 @@ def __init__(self, hp: hydpytools.HydPy, targetfunction: TargetFunction):
self._logfilelines = collections.deque()
self.result = None

def add_rules(self, *rules: RuleType1) -> None:
def add_rules(self, *rules: TypeRule1) -> None:
"""Add some |Rule| objects to the actual |CalibrationInterface| object.
>>> from hydpy.examples import prepare_full_example_2
Expand Down Expand Up @@ -1531,16 +1531,16 @@ def add_rules(self, *rules: RuleType1) -> None:
self._update_elements_when_adding_a_rule(rule)

@overload
def get_rule(self, name: str) -> RuleType1:
def get_rule(self, name: str) -> TypeRule1:
...

@overload
def get_rule(self, name: str, type_: Type[RuleType2]) -> RuleType2:
def get_rule(self, name: str, type_: Type[TypeRule2]) -> TypeRule2:
...

def get_rule(
self, name: str, type_: Optional[Type[RuleType2]] = None
) -> Union[RuleType1, RuleType2]:
self, name: str, type_: Optional[Type[TypeRule2]] = None
) -> Union[TypeRule1, TypeRule2]:
"""Return a |Rule| object (of a specific type).
Method |CalibrationInterface.get_rule| is a more typesafe alternative to simple
Expand Down Expand Up @@ -1596,7 +1596,7 @@ def get_rule(
f"`{name}` of type `{type_.__name__}`."
)

def remove_rules(self, *rules: Union[str, RuleType1]) -> None:
def remove_rules(self, *rules: Union[str, TypeRule1]) -> None:
"""Remove some |Rule| objects from the actual |CalibrationInterface| object.
>>> from hydpy.examples import prepare_full_example_2
Expand Down Expand Up @@ -1792,7 +1792,7 @@ def read_logfile(
idx2rule[idx].value = float(value)
self.result = result_best

def _update_elements_when_adding_a_rule(self, rule: RuleType1) -> None:
def _update_elements_when_adding_a_rule(self, rule: TypeRule1) -> None:
self._elements += rule.elements

def _update_elements_when_deleting_a_rule(self) -> None:
Expand Down Expand Up @@ -2151,11 +2151,11 @@ def print_table(
def __len__(self) -> int:
return len(self._rules)

def __iter__(self) -> Iterator[RuleType1]:
def __iter__(self) -> Iterator[TypeRule1]:
for rule in self._rules.values():
yield rule

def __getattr__(self, item: str) -> RuleType1:
def __getattr__(self, item: str) -> TypeRule1:
try:
return self._rules[item]
except KeyError:
Expand All @@ -2164,7 +2164,7 @@ def __getattr__(self, item: str) -> RuleType1:
f"attribute nor a rule object named `{item}`."
) from None

def __getitem__(self, key: str) -> RuleType1:
def __getitem__(self, key: str) -> TypeRule1:
try:
return self._rules[key]
except KeyError:
Expand Down Expand Up @@ -2928,7 +2928,7 @@ def __dir__(self) -> List[str]:
@overload
def make_rules(
*,
rule: Type[RuleType],
rule: Type[TypeRule],
names: Sequence[str],
parameters: Sequence[Union[parametertools.Parameter, str]],
values: Sequence[float],
Expand All @@ -2937,14 +2937,14 @@ def make_rules(
parametersteps: Sequence1[Optional[timetools.PeriodConstrArg]] = None,
model: Optional[Union[types.ModuleType, str]] = None,
selections: Literal[None] = None,
) -> List[RuleType]:
) -> List[TypeRule]:
...


@overload
def make_rules(
*,
rule: Type[RuleType],
rule: Type[TypeRule],
names: Sequence[str],
parameters: Sequence[Union[parametertools.Parameter, str]],
values: Sequence[float],
Expand All @@ -2955,14 +2955,14 @@ def make_rules(
model: Optional[Union[types.ModuleType, str]] = None,
selections: Iterable[Union[selectiontools.Selection, str]],
product: bool = False,
) -> List[RuleType]:
) -> List[TypeRule]:
...


@overload
def make_rules(
*,
rule: Type[RuleType],
rule: Type[TypeRule],
calibspecs: "CalibSpecs",
names: Optional[Sequence[str]] = None,
parameters: Optional[Sequence[Union[parametertools.Parameter, str]]] = None,
Expand All @@ -2972,14 +2972,14 @@ def make_rules(
uppers: Optional[Sequence[float]] = None,
model: Optional[Union[types.ModuleType, str]] = None,
selections: Literal[None] = None,
) -> List[RuleType]:
) -> List[TypeRule]:
...


@overload
def make_rules(
*,
rule: Type[RuleType],
rule: Type[TypeRule],
calibspecs: "CalibSpecs",
names: Optional[Sequence[str]] = None,
parameters: Optional[Sequence[Union[parametertools.Parameter, str]]] = None,
Expand All @@ -2990,13 +2990,13 @@ def make_rules(
model: Optional[Union[types.ModuleType, str]] = None,
selections: Iterable[Union[selectiontools.Selection, str]],
product: bool = False,
) -> List[RuleType]:
) -> List[TypeRule]:
...


def make_rules(
*,
rule: Type[RuleType],
rule: Type[TypeRule],
calibspecs: Optional["CalibSpecs"] = None,
names: Optional[Sequence[str]] = None,
parameters: Optional[Sequence[Union[parametertools.Parameter, str]]] = None,
Expand All @@ -3008,7 +3008,7 @@ def make_rules(
model: Optional[Union[types.ModuleType, str]] = None,
selections: Optional[Iterable[Union[selectiontools.Selection, str]]] = None,
product: bool = False,
) -> List[RuleType]:
) -> List[TypeRule]:
"""Conveniently create multiple |Rule| objects at once.
Please see the main documentation on class |CalibrationInterface| first, from
Expand Down
20 changes: 10 additions & 10 deletions hydpy/auxs/xmltools.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,14 @@
)
xmlschema = exceptiontools.OptionalImport("xmlschema", ["xmlschema"], locals())

_SetOrAddOrMultiplyItem = TypeVar(
"_SetOrAddOrMultiplyItem",
_TypeSetOrAddOrMultiplyItem = TypeVar(
"_TypeSetOrAddOrMultiplyItem",
itemtools.SetItem,
itemtools.AddItem,
itemtools.MultiplyItem,
)
_GetOrChangeItem = TypeVar(
"_GetOrChangeItem",
_TypeGetOrChangeItem = TypeVar(
"_TypeSetOrAddOrMultiplyItem",
itemtools.GetItem,
itemtools.ChangeItem,
itemtools.SetItem,
Expand Down Expand Up @@ -1719,10 +1719,10 @@ def __init__(self, master: XMLInterface, root: ElementTree.Element) -> None:
self.root: ElementTree.Element = root

def _get_items_of_certain_item_types(
self, itemgroups: Iterable[str], itemtype: Type[_GetOrChangeItem]
) -> List[_GetOrChangeItem]:
self, itemgroups: Iterable[str], itemtype: Type[_TypeGetOrChangeItem]
) -> List[_TypeGetOrChangeItem]:
"""Return either all |GetItem| or all |ChangeItem| objects."""
items: List[_GetOrChangeItem] = []
items: List[_TypeGetOrChangeItem] = []
for itemgroup in self.itemgroups:
if (
issubclass(itemtype, itemtools.GetItem)
Expand Down Expand Up @@ -2200,13 +2200,13 @@ def _get_getitem(
return item

def _get_changeitem(
self, target: str, master: str, itemtype: Type[_SetOrAddOrMultiplyItem]
) -> _SetOrAddOrMultiplyItem:
self, target: str, master: str, itemtype: Type[_TypeSetOrAddOrMultiplyItem]
) -> _TypeSetOrAddOrMultiplyItem:
name = cast(Name, self.find("name", optional=False).text)
assert name is not None
level = self.find("level", optional=False).text
assert level is not None
item: _SetOrAddOrMultiplyItem
item: _TypeSetOrAddOrMultiplyItem
# Simplify the following if-clauses after Mypy issue 10989 is fixed?
if not issubclass(itemtype, itemtools.SetItem):
item = itemtype(
Expand Down
4 changes: 2 additions & 2 deletions hydpy/core/aliastools.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def __init__(
self._alias = alias
self._namespace = namespace

def _get_sequencetype(self) -> sequencetools.TypesInOutSequence:
def _get_sequencetype(self) -> sequencetools.InOutSequenceTypes:
dict_ = object.__getattribute__(self, "__dict__")
module = importlib.import_module(dict_["_modulename"])
return getattr(module, dict_["_classname"]) # type: ignore[no-any-return]
Expand Down Expand Up @@ -165,7 +165,7 @@ def write_sequencealiases() -> None:
"outputs.py",
),
):
sequence2alias: Dict[sqt.TypesInOutSequence, str] = {}
sequence2alias: Dict[sqt.InOutSequenceTypes, str] = {}
for moduleinfo in pkgutil.walk_packages([modelpath]):
if not moduleinfo.ispkg:
continue
Expand Down
Loading

0 comments on commit 25c62ce

Please sign in to comment.