diff --git a/hydpy/__init__.py b/hydpy/__init__.py index 16d81b6df0..cc3b6035b5 100644 --- a/hydpy/__init__.py +++ b/hydpy/__init__.py @@ -310,7 +310,7 @@ "start_server", ] -sequence2alias: Dict[sequencetools.TypesInOutSequence, str] = {} +sequence2alias: Dict[sequencetools.InOutSequenceTypes, str] = {} if config.USEAUTODOC: with warnings.catch_warnings(): diff --git a/hydpy/auxs/anntools.py b/hydpy/auxs/anntools.py index 631fb6c5f0..066df3bcf0 100644 --- a/hydpy/auxs/anntools.py +++ b/hydpy/auxs/anntools.py @@ -24,8 +24,8 @@ class _ANNArrayProperty( propertytools.DependentProperty[ - propertytools.InputType, - propertytools.OutputType, + propertytools.TypeInput, + propertytools.TypeOutput, ], ): @@ -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: diff --git a/hydpy/auxs/calibtools.py b/hydpy/auxs/calibtools.py index d203d14ea6..e0436e5c53 100644 --- a/hydpy/auxs/calibtools.py +++ b/hydpy/auxs/calibtools.py @@ -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] @@ -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. @@ -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] @@ -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, @@ -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, @@ -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 @@ -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): @@ -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 @@ -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 @@ -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 @@ -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: @@ -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: @@ -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: @@ -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], @@ -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], @@ -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, @@ -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, @@ -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, @@ -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 diff --git a/hydpy/auxs/xmltools.py b/hydpy/auxs/xmltools.py index 949da987f5..775965e842 100644 --- a/hydpy/auxs/xmltools.py +++ b/hydpy/auxs/xmltools.py @@ -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, @@ -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) @@ -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( diff --git a/hydpy/core/aliastools.py b/hydpy/core/aliastools.py index 8398c41fe4..d77901f439 100644 --- a/hydpy/core/aliastools.py +++ b/hydpy/core/aliastools.py @@ -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] @@ -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 diff --git a/hydpy/core/devicetools.py b/hydpy/core/devicetools.py index 521e5fad57..e828beb1e8 100644 --- a/hydpy/core/devicetools.py +++ b/hydpy/core/devicetools.py @@ -107,9 +107,9 @@ class |Device| directly). On the other hand, "nodes", for example, does not _default_variable = "Q" -DeviceType = TypeVar("DeviceType", "Node", "Element") -DevicesTypeBound = TypeVar("DevicesTypeBound", bound="Devices") -DevicesTypeUnbound = TypeVar("DevicesTypeUnbound", "Nodes", "Elements") +TypeDevice = TypeVar("TypeDevice", "Node", "Element") +TypeDevicesBound = TypeVar("TypeDevicesBound", bound="Devices") +TypeDevicesUnbound = TypeVar("TypeDevicesUnbound", "Nodes", "Elements") NodesConstrArg = MayNonerable2["Node", str] ElementsConstrArg = MayNonerable2["Element", str] @@ -118,7 +118,7 @@ class |Device| directly). On the other hand, "nodes", for example, does not NodeVariableType = Union[ str, - sequencetools.TypesInOutSequence, + sequencetools.InOutSequenceTypes, "FusedVariable", ] @@ -423,11 +423,11 @@ class FusedVariable: _name: str _aliases: Tuple[str] - _variables: Tuple[sequencetools.TypesInOutSequence, ...] - _alias2variable: Dict[str, sequencetools.TypesInOutSequence] + _variables: Tuple[sequencetools.InOutSequenceTypes, ...] + _alias2variable: Dict[str, sequencetools.InOutSequenceTypes] def __new__( - cls, name: str, *sequences: sequencetools.TypesInOutSequence + cls, name: str, *sequences: sequencetools.InOutSequenceTypes ) -> FusedVariable: self = super().__new__(cls) aliases = tuple(hydpy.sequence2alias[seq] for seq in sequences) @@ -465,7 +465,7 @@ def clear_registry(cls) -> None: """ return _registry_fusedvariable.clear() - def __iter__(self) -> Iterator[sequencetools.TypesInOutSequence]: + def __iter__(self) -> Iterator[sequencetools.InOutSequenceTypes]: for variable in self._variables: yield variable @@ -484,7 +484,7 @@ def __repr__(self) -> str: return f'FusedVariable("{self._name}", {", ".join(self._aliases)})' -class Devices(Generic[DeviceType]): +class Devices(Generic[TypeDevice]): """Base class for class |Elements| and class |Nodes|. The following features are common to class |Nodes| and class |Elements|. We @@ -635,7 +635,7 @@ class Devices(Generic[DeviceType]): classes: Node and str. """ - _name2device: Dict[str, DeviceType] + _name2device: Dict[str, TypeDevice] mutable: bool _shadowed_keywords: Set[str] forceiterable: bool = False @@ -643,7 +643,7 @@ class Devices(Generic[DeviceType]): # We do not want to implement the signature of Generic.__new__ here: def __new__( # pylint: disable=arguments-differ cls, - *values: MayNonerable2[DeviceType, str], + *values: MayNonerable2[TypeDevice, str], mutable: bool = True, ): if len(values) == 1 and isinstance(values[0], Devices): @@ -667,10 +667,10 @@ def __new__( # pylint: disable=arguments-differ @staticmethod @abc.abstractmethod - def get_contentclass() -> Type[DeviceType]: + def get_contentclass() -> Type[TypeDevice]: """To be overridden.""" - def add_device(self, device: Union[DeviceType, str]) -> None: + def add_device(self, device: Union[TypeDevice, str]) -> None: """Add the given |Node| or |Element| object to the actual |Nodes| or |Elements| object. @@ -711,7 +711,7 @@ def add_device(self, device: Union[DeviceType, str]) -> None: f"{type(self).__name__} object" ) - def remove_device(self, device: Union[DeviceType, str]) -> None: + def remove_device(self, device: Union[TypeDevice, str]) -> None: """Remove the given |Node| or |Element| object from the actual |Nodes| or |Elements| object. @@ -776,7 +776,7 @@ def names(self) -> Tuple[str, ...]: return tuple(device.name for device in self) @property - def devices(self) -> Tuple[DeviceType, ...]: + def devices(self) -> Tuple[TypeDevice, ...]: """A tuple of the handled devices sorted by the device names. >>> from hydpy import Nodes @@ -848,9 +848,9 @@ def keywords(self) -> Set[str]: ) def search_keywords( - self: DevicesTypeBound, + self: TypeDevicesBound, *keywords: str, - ) -> DevicesTypeBound: + ) -> TypeDevicesBound: """Search for all devices handling at least one of the given keywords and return them. @@ -876,7 +876,7 @@ def search_keywords( *(device for device in self if keywords_.intersection(device.keywords)) ) - def copy(self: DevicesTypeBound) -> DevicesTypeBound: + def copy(self: TypeDevicesBound) -> TypeDevicesBound: """Return a shallow copy of the actual |Nodes| or |Elements| object. Method |Devices.copy| returns a semi-flat copy of |Nodes| or |Elements| objects @@ -922,9 +922,9 @@ def copy(self: DevicesTypeBound) -> DevicesTypeBound: return new def intersection( - self: DevicesTypeBound, - *other: DeviceType, - ) -> DevicesTypeBound: + self: TypeDevicesBound, + *other: TypeDevice, + ) -> TypeDevicesBound: """Return the intersection with the given |Devices| object. >>> from hydpy import Node, Nodes @@ -949,16 +949,16 @@ def __deepcopy__(self, dict_): f"which is in conflict with using their names as identifiers." ) - def __select_devices_by_keyword(self, name: str) -> DevicesTypeBound: + def __select_devices_by_keyword(self, name: str) -> TypeDevicesBound: devices = type(self)(*(device for device in self if name in device.keywords)) vars(devices)["_shadowed_keywords"] = self._shadowed_keywords.copy() vars(devices)["_shadowed_keywords"].add(name) return devices def __getattr__( - self: DevicesTypeBound, + self: TypeDevicesBound, name: str, - ) -> Union[DeviceType, DevicesTypeBound]: + ) -> Union[TypeDevice, TypeDevicesBound]: try: name2device = self._name2device device = name2device[name] @@ -1000,19 +1000,19 @@ def __delattr__(self, name: str) -> None: f"could be removed, and deleting other attributes is not supported." ) from None - def __getitem__(self, name: str) -> DeviceType: + def __getitem__(self, name: str) -> TypeDevice: try: return self._name2device[name] except KeyError: raise KeyError(f"No device named `{name}` available.") from None - def __setitem__(self, name: str, value: DeviceType) -> None: + def __setitem__(self, name: str, value: TypeDevice) -> None: self._name2device[name] = value def __delitem__(self, name: str) -> None: del self._name2device[name] - def __iter__(self) -> Iterator[DeviceType]: + def __iter__(self) -> Iterator[TypeDevice]: for (_, device) in sorted(self._name2device.items()): yield device @@ -1028,9 +1028,9 @@ def __len__(self) -> int: return len(self._name2device) def __add__( - self: DevicesTypeBound, - other: Mayberable2[DeviceType, str], - ) -> DevicesTypeBound: + self: TypeDevicesBound, + other: Mayberable2[TypeDevice, str], + ) -> TypeDevicesBound: new = copy.copy(self) new.mutable = True for device in type(self)(other): @@ -1038,17 +1038,17 @@ def __add__( return new def __iadd__( - self: DevicesTypeBound, - other: Mayberable2[DeviceType, str], - ) -> DevicesTypeBound: + self: TypeDevicesBound, + other: Mayberable2[TypeDevice, str], + ) -> TypeDevicesBound: for device in type(self)(other): self.add_device(device) return self def __sub__( - self: DevicesTypeBound, - other: Mayberable2[DeviceType, str], - ) -> DevicesTypeBound: + self: TypeDevicesBound, + other: Mayberable2[TypeDevice, str], + ) -> TypeDevicesBound: new = copy.copy(self) new.mutable = True for device in type(self)(other): @@ -1059,9 +1059,9 @@ def __sub__( return new def __isub__( - self: DevicesTypeBound, - other: Mayberable2[DeviceType, str], - ) -> DevicesTypeBound: + self: TypeDevicesBound, + other: Mayberable2[TypeDevice, str], + ) -> TypeDevicesBound: for device in type(self)(other): try: self.remove_device(device) @@ -1074,10 +1074,10 @@ def __compare(self, other: object, func: Callable[[object, object], bool]) -> bo return func(set(self), set(other)) return NotImplemented - def __lt__(self, other: DevicesTypeBound) -> bool: + def __lt__(self, other: TypeDevicesBound) -> bool: return self.__compare(other, operator.lt) - def __le__(self, other: DevicesTypeBound) -> bool: + def __le__(self, other: TypeDevicesBound) -> bool: return self.__compare(other, operator.le) def __eq__(self, other: Any) -> bool: @@ -1086,10 +1086,10 @@ def __eq__(self, other: Any) -> bool: def __ne__(self, other: Any) -> bool: return self.__compare(other, operator.ne) - def __ge__(self, other: DevicesTypeBound) -> bool: + def __ge__(self, other: TypeDevicesBound) -> bool: return self.__compare(other, operator.ge) - def __gt__(self, other: DevicesTypeBound) -> bool: + def __gt__(self, other: TypeDevicesBound) -> bool: return self.__compare(other, operator.gt) def __repr__(self) -> str: @@ -1142,7 +1142,7 @@ class |Devices|. def __new__( cls, - *values: MayNonerable2[DeviceType, str], + *values: MayNonerable2[TypeDevice, str], mutable: bool = True, defaultvariable: NodeVariableType = "Q", ): @@ -1526,7 +1526,7 @@ def __save_modelseries(self, name_subseqs: str) -> None: element.model.sequences[name_subseqs].save_series() -class Device(Generic[DevicesTypeUnbound]): +class Device(Generic[TypeDevicesUnbound]): """Base class for class |Element| and class |Node|.""" def __new__(cls, value, *args, **kwargs): @@ -1553,7 +1553,7 @@ def get_handlerclass(cls) -> Type: """To be overridden.""" @classmethod - def query_all(cls) -> DevicesTypeUnbound: + def query_all(cls) -> TypeDevicesUnbound: """Get all |Node| or |Element| objects initialised so far. See the main documentation on module |devicetools| for further information. @@ -1561,7 +1561,7 @@ def query_all(cls) -> DevicesTypeUnbound: return cls.get_handlerclass()(*_registry[cls].values()) @classmethod - def extract_new(cls) -> DevicesTypeUnbound: + def extract_new(cls) -> TypeDevicesUnbound: """Gather all "new" |Node| or |Element| objects. See the main documentation on module |devicetools| for further information. diff --git a/hydpy/core/propertytools.py b/hydpy/core/propertytools.py index fb6713f7e0..f03cc03d45 100644 --- a/hydpy/core/propertytools.py +++ b/hydpy/core/propertytools.py @@ -18,10 +18,10 @@ from hydpy.core import objecttools from hydpy.core.typingtools import * -InputType = TypeVar("InputType") -InputType_contra = TypeVar("InputType_contra", contravariant=True) -OutputType = TypeVar("OutputType") -OutputType_co = TypeVar("OutputType_co", covariant=True) +TypeInput = TypeVar("TypeInput") +TypeInput_contra = TypeVar("TypeInput_contra", contravariant=True) +TypeOutput = TypeVar("TypeOutput") +TypeOutput_co = TypeVar("TypeOutput_co", covariant=True) class BaseDescriptor: @@ -57,17 +57,17 @@ def __set_name__( self.set_doc(doc) -class FGet(Protocol[OutputType_co]): +class FGet(Protocol[TypeOutput_co]): """Callback protocol for getter functions.""" - def __call__(self, __obj: Any) -> OutputType_co: + def __call__(self, __obj: Any) -> TypeOutput_co: ... -class FSet(Protocol[InputType_contra]): +class FSet(Protocol[TypeInput_contra]): """Callback protocol for setter functions.""" - def __call__(self, __obj: Any, __value: InputType_contra) -> None: + def __call__(self, __obj: Any, __value: TypeInput_contra) -> None: ... @@ -78,7 +78,7 @@ def __call__(self, __obj: Any) -> None: ... -class BaseProperty(Generic[InputType, OutputType], BaseDescriptor): +class BaseProperty(Generic[TypeInput, TypeOutput], BaseDescriptor): """Abstract base class for deriving classes similar to |property|. |BaseProperty| provides the abstract methods |BaseProperty.call_fget|, @@ -109,16 +109,16 @@ class BaseProperty(Generic[InputType, OutputType], BaseDescriptor): RuntimeError """ - fget: FGet[OutputType] - fset: FSet[InputType] + fget: FGet[TypeOutput] + fset: FSet[TypeInput] fdel: FDel @staticmethod - def _fgetdummy(__obj: Any) -> OutputType: + def _fgetdummy(__obj: Any) -> TypeOutput: raise RuntimeError @staticmethod - def _fsetdummy(__obj: Any, __value: InputType) -> None: + def _fsetdummy(__obj: Any, __value: TypeInput) -> None: raise RuntimeError @staticmethod @@ -128,16 +128,16 @@ def _fdeldummy(__obj: Any) -> None: @overload def __get__( self, obj: None, objtype: Type[Any] - ) -> BaseProperty[InputType, OutputType]: + ) -> BaseProperty[TypeInput, TypeOutput]: ... @overload - def __get__(self, obj: Any, objtype: Type[Any]) -> OutputType: + def __get__(self, obj: Any, objtype: Type[Any]) -> TypeOutput: ... def __get__( self, obj: Optional[Any], objtype: Type[Any] - ) -> Union[BaseProperty[InputType, OutputType], OutputType]: + ) -> Union[BaseProperty[TypeInput, TypeOutput], TypeOutput]: if obj is None: return self if self.fget is self._fgetdummy: @@ -147,7 +147,7 @@ def __get__( ) return self.call_fget(obj) - def __set__(self, obj: Any, value: InputType) -> None: + def __set__(self, obj: Any, value: TypeInput) -> None: if self.fset is self._fsetdummy: raise AttributeError( f"Attribute `{self.name}` of object " @@ -164,11 +164,11 @@ def __delete__(self, obj: Any) -> None: self.call_fdel(obj) @abc.abstractmethod - def call_fget(self, obj: Any) -> OutputType: + def call_fget(self, obj: Any) -> TypeOutput: """Method for implementing unique getter functionalities.""" @abc.abstractmethod - def call_fset(self, obj: Any, value: InputType) -> None: + def call_fset(self, obj: Any, value: TypeInput) -> None: """Method for implementing unique setter functionalities.""" @abc.abstractmethod @@ -176,7 +176,7 @@ def call_fdel(self, obj: Any) -> None: """Method for implementing unique deleter functionalities.""" -class Property(BaseProperty[InputType, OutputType]): +class Property(BaseProperty[TypeInput, TypeOutput]): """Class |Property| mimics the behaviour of the built-in function |property|. The only advantage of |Property| over |property| is that it allows defining @@ -236,8 +236,8 @@ class Property(BaseProperty[InputType, OutputType]): def __init__( self, - fget: FGet[OutputType] = BaseProperty._fgetdummy, - fset: FSet[InputType] = BaseProperty._fsetdummy, + fget: FGet[TypeOutput] = BaseProperty._fgetdummy, + fset: FSet[TypeInput] = BaseProperty._fsetdummy, fdel: FDel = BaseProperty._fdeldummy, ) -> None: self.fget = fget @@ -245,11 +245,11 @@ def __init__( self.fset = fset self.fdel = fdel - def call_fget(self, obj: Any) -> OutputType: + def call_fget(self, obj: Any) -> TypeOutput: """Call `fget` without additional functionalities.""" return self.fget(obj) - def call_fset(self, obj: Any, value: InputType) -> None: + def call_fset(self, obj: Any, value: TypeInput) -> None: """Call `fset` without additional functionalities.""" self.fset(obj, value) @@ -257,25 +257,25 @@ def call_fdel(self, obj: Any) -> None: """Call `fdel` without additional functionalities.""" self.fdel(obj) - def getter(self, fget: FGet[OutputType]) -> Property[InputType, OutputType]: + def getter(self, fget: FGet[TypeOutput]) -> Property[TypeInput, TypeOutput]: """Add the given getter function and its docstring to the property and return it.""" self.fget = fget self.set_doc(fget.__doc__) return self - def setter(self, fset: FSet[InputType]) -> Property[InputType, OutputType]: + def setter(self, fset: FSet[TypeInput]) -> Property[TypeInput, TypeOutput]: """Add the given setter function to the property and return it.""" self.fset = fset return self - def deleter(self, fdel: FDel) -> Property[InputType, OutputType]: + def deleter(self, fdel: FDel) -> Property[TypeInput, TypeOutput]: """Add the given deleter function to the property and return it.""" setattr(self, "fdel", fdel) return self -class ProtectedProperty(BaseProperty[InputType, OutputType]): +class ProtectedProperty(BaseProperty[TypeInput, TypeOutput]): """A |property|-like class which prevents getting an attribute before setting it. Some attributes need preparations before being accessible. Consider the case @@ -334,8 +334,8 @@ class ProtectedProperty(BaseProperty[InputType, OutputType]): def __init__( self, - fget: FGet[OutputType] = BaseProperty._fgetdummy, - fset: FSet[InputType] = BaseProperty._fsetdummy, + fget: FGet[TypeOutput] = BaseProperty._fgetdummy, + fset: FSet[TypeInput] = BaseProperty._fsetdummy, fdel: FDel = BaseProperty._fdeldummy, ) -> None: self.fget = fget @@ -343,7 +343,7 @@ def __init__( self.fset = fset self.fdel = fdel - def call_fget(self, obj: Any) -> OutputType: + def call_fget(self, obj: Any) -> TypeOutput: """When ready, call `fget`; otherwise, raise an |AttributeNotReady| exception.""" if self.isready(obj): @@ -353,7 +353,7 @@ def call_fget(self, obj: Any) -> OutputType: f"has not been prepared so far." ) - def call_fset(self, obj: Any, value: InputType) -> None: + def call_fset(self, obj: Any, value: TypeInput) -> None: """Call `fset` and mark the attribute as ready.""" self.fset(obj, value) vars(obj)[self.name] = True @@ -370,20 +370,20 @@ def isready(self, obj: Any) -> bool: return vars(obj).get(self.name, False) def getter( - self, fget: FGet[OutputType] - ) -> "ProtectedProperty[InputType, OutputType]": + self, fget: FGet[TypeOutput] + ) -> "ProtectedProperty[TypeInput, TypeOutput]": """Add the given getter function and its docstring to the property and return it.""" self.fget = fget self.set_doc(fget.__doc__) return self - def setter(self, fset: FSet[InputType]) -> ProtectedProperty[InputType, OutputType]: + def setter(self, fset: FSet[TypeInput]) -> ProtectedProperty[TypeInput, TypeOutput]: """Add the given setter function to the property and return it.""" self.fset = fset return self - def deleter(self, fdel: FDel) -> ProtectedProperty[InputType, OutputType]: + def deleter(self, fdel: FDel) -> ProtectedProperty[TypeInput, TypeOutput]: """Add the given deleter function to the property and return it.""" self.fdel = fdel return self @@ -447,7 +447,7 @@ def __iter__(self) -> Iterator[ProtectedProperty[Any, Any]]: return self.__properties.__iter__() -class DependentProperty(BaseProperty[InputType, OutputType]): +class DependentProperty(BaseProperty[TypeInput, TypeOutput]): """|property|-like class which prevents accessing a dependent attribute before preparing certain other attributes. @@ -519,8 +519,8 @@ class DependentProperty(BaseProperty[InputType, OutputType]): def __init__( self, protected: ProtectedProperties, - fget: FGet[OutputType] = BaseProperty._fgetdummy, - fset: FSet[InputType] = BaseProperty._fsetdummy, + fget: FGet[TypeOutput] = BaseProperty._fgetdummy, + fset: FSet[TypeInput] = BaseProperty._fsetdummy, fdel: FDel = BaseProperty._fdeldummy, ) -> None: self.protected = protected @@ -539,13 +539,13 @@ def __check(self, obj: Any) -> None: f"`{req.name}` first." ) - def call_fget(self, obj: Any) -> OutputType: + def call_fget(self, obj: Any) -> TypeOutput: """Call `fget` when all required attributes are ready; otherwise, raise an |AttributeNotReady| error.""" self.__check(obj) return self.fget(obj) - def call_fset(self, obj: Any, value: InputType) -> None: + def call_fset(self, obj: Any, value: TypeInput) -> None: """Call `fset` when all required attributes are ready; otherwise, raise an |AttributeNotReady| error.""" self.__check(obj) @@ -558,26 +558,26 @@ def call_fdel(self, obj: Any) -> None: self.fdel(obj) def getter( - self, fget: FGet[OutputType] - ) -> DependentProperty[InputType, OutputType]: + self, fget: FGet[TypeOutput] + ) -> DependentProperty[TypeInput, TypeOutput]: """Add the given getter function and its docstring to the property and return it.""" self.fget = fget self.set_doc(fget.__doc__) return self - def setter(self, fset: FSet[InputType]) -> DependentProperty[InputType, OutputType]: + def setter(self, fset: FSet[TypeInput]) -> DependentProperty[TypeInput, TypeOutput]: """Add the given setter function to the property and return it.""" self.fset = fset return self - def deleter(self, fdel: FDel) -> DependentProperty[InputType, OutputType]: + def deleter(self, fdel: FDel) -> DependentProperty[TypeInput, TypeOutput]: """Add the given deleter function to the property and return it.""" self.fdel = fdel return self -class DefaultProperty(BaseProperty[InputType, OutputType]): +class DefaultProperty(BaseProperty[TypeInput, TypeOutput]): """|property|-like class which uses the getter function to return a default value unless a custom value is available. @@ -621,21 +621,21 @@ class DefaultProperty(BaseProperty[InputType, OutputType]): 'Default property x.' """ - def __init__(self, fget: FGet[OutputType] = BaseProperty._fgetdummy) -> None: + def __init__(self, fget: FGet[TypeOutput] = BaseProperty._fgetdummy) -> None: self.fget = fget self.set_doc(fget.__doc__) self.fset = self._fsetowndummy self.fdel = self._fdelowndummy - def call_fget(self, obj: Any) -> OutputType: + def call_fget(self, obj: Any) -> TypeOutput: """If available, return the predefined custom value; otherwise, return the value defined by the getter function.""" - value = cast(Optional[OutputType], vars(obj).get(self.name)) + value = cast(Optional[TypeOutput], vars(obj).get(self.name)) if value is None: return self.fget(obj) return value - def call_fset(self, obj: Any, value: InputType) -> None: + def call_fset(self, obj: Any, value: TypeInput) -> None: """Store the given custom value.""" vars(obj)[self.name] = value @@ -647,7 +647,7 @@ def call_fdel(self, obj: Any) -> None: pass @staticmethod - def _fsetowndummy(__obj: Any, __value: InputType) -> None: + def _fsetowndummy(__obj: Any, __value: TypeInput) -> None: """Do nothing.""" @staticmethod diff --git a/hydpy/core/pubtools.py b/hydpy/core/pubtools.py index e88f7e9272..fe8450b429 100644 --- a/hydpy/core/pubtools.py +++ b/hydpy/core/pubtools.py @@ -22,8 +22,8 @@ class _PubProperty( propertytools.DefaultProperty[ - propertytools.InputType, - propertytools.OutputType, + propertytools.TypeInput, + propertytools.TypeOutput, ] ): def __init__(self) -> None: diff --git a/hydpy/core/selectiontools.py b/hydpy/core/selectiontools.py index d283289547..0e670c2f7d 100644 --- a/hydpy/core/selectiontools.py +++ b/hydpy/core/selectiontools.py @@ -253,7 +253,7 @@ def remove_selections(self, *selections: Selection) -> None: except KeyError: pass - def find(self, device: devicetools.DeviceType) -> Selections: + def find(self, device: devicetools.TypeDevice) -> Selections: """Return all |Selection| objects containing the given |Node| or |Element| object. @@ -662,8 +662,8 @@ def __init__( self.elements = devicetools.Elements(elements).copy() def _check_device( - self, device: devicetools.DeviceType, type_of_device: str - ) -> devicetools.DeviceType: + self, device: devicetools.TypeDevice, type_of_device: str + ) -> devicetools.TypeDevice: if isinstance(device, devicetools.Node): device = self.nodes[device.name] elif isinstance(device, devicetools.Element): @@ -678,7 +678,7 @@ def _check_device( def search_upstream( self, - device: devicetools.DeviceType, + device: devicetools.TypeDevice, name: str = "upstream", inclusive: bool = True, ) -> Selection: @@ -804,7 +804,7 @@ def search_upstream( ) def select_upstream( - self, device: devicetools.DeviceType, inclusive: bool = True + self, device: devicetools.TypeDevice, inclusive: bool = True ) -> Selection: """Restrict the current selection to the network upstream of the given starting point, including the starting point itself. @@ -818,7 +818,7 @@ def select_upstream( return self def deselect_upstream( - self, device: devicetools.DeviceType, inclusive: bool = True + self, device: devicetools.TypeDevice, inclusive: bool = True ) -> Selection: """Remove the network upstream of the given starting point from the current selection, including the starting point itself. @@ -833,7 +833,7 @@ def deselect_upstream( def search_downstream( self, - device: devicetools.DeviceType, + device: devicetools.TypeDevice, name: str = "downstream", inclusive: bool = True, ) -> Selection: @@ -954,7 +954,7 @@ def search_downstream( ) def select_downstream( - self, device: devicetools.DeviceType, inclusive: bool = True + self, device: devicetools.TypeDevice, inclusive: bool = True ) -> Selection: """Restrict the current selection to the network downstream of the given starting point, including the starting point itself. @@ -968,7 +968,7 @@ def select_downstream( return self def deselect_downstream( - self, device: devicetools.DeviceType, inclusive: bool = True + self, device: devicetools.TypeDevice, inclusive: bool = True ) -> Selection: """Remove the network downstream of the given starting point from the current selection, including the starting point itself. diff --git a/hydpy/core/sequencetools.py b/hydpy/core/sequencetools.py index d251cf3619..1a25839d3d 100644 --- a/hydpy/core/sequencetools.py +++ b/hydpy/core/sequencetools.py @@ -33,30 +33,30 @@ InOutSequence = Union["InputSequence", "OutputSequence"] -TypesInOutSequence = Union[Type["InputSequence"], Type["OutputSequence"]] +InOutSequenceTypes = Union[Type["InputSequence"], Type["OutputSequence"]] -SequencesType = TypeVar("SequencesType", "Sequences", "devicetools.Node") +TypeSequences = TypeVar("TypeSequences", "Sequences", "devicetools.Node") -SubSequencesType = TypeVar("SubSequencesType", bound="SubSequences") -SequenceType = TypeVar("SequenceType", bound="Sequence_") +TypeSubSequences = TypeVar("TypeSubSequences", bound="SubSequences") +TypeSequence = TypeVar("TypeSequence", bound="Sequence_") -IOSequencesType = TypeVar("IOSequencesType", bound="IOSequences") -IOSequenceType = TypeVar("IOSequenceType", bound="IOSequence") -FastAccessIOSequenceType = TypeVar( - "FastAccessIOSequenceType", bound="FastAccessIOSequence" +TypeIOSequences = TypeVar("TypeIOSequences", bound="IOSequences") +TypeIOSequence = TypeVar("TypeIOSequence", bound="IOSequence") +TypeFastAccessIOSequence = TypeVar( + "TypeFastAccessIOSequence", bound="FastAccessIOSequence" ) -ModelSequencesType = TypeVar("ModelSequencesType", bound="ModelSequences") -ModelSequenceType = TypeVar("ModelSequenceType", bound="ModelSequence") +TypeModelSequences = TypeVar("TypeModelSequences", bound="ModelSequences") +TypeModelSequence = TypeVar("TypeModelSequence", bound="ModelSequence") -ModelIOSequencesType = TypeVar("ModelIOSequencesType", bound="ModelIOSequences") -ModelIOSequenceType = TypeVar("ModelIOSequenceType", bound="ModelIOSequence") +TypeModelIOSequences = TypeVar("TypeModelIOSequences", bound="ModelIOSequences") +TypeModelIOSequence = TypeVar("TypeModelIOSequence", bound="ModelIOSequence") -OutputSequencesType = TypeVar("OutputSequencesType", bound="OutputSequences") -OutputSequenceType = TypeVar("OutputSequenceType", bound="OutputSequence") +TypeOutputSequences = TypeVar("TypeOutputSequences", bound="OutputSequences") +TypeOutputSequence = TypeVar("TypeOutputSequence", bound="OutputSequence") -LinkSequencesType = TypeVar("LinkSequencesType", bound="LinkSequences") -LinkSequenceType = TypeVar("LinkSequenceType", bound="LinkSequence") +TypeLinkSequences = TypeVar("TypeLinkSequences", bound="LinkSequences") +TypeLinkSequence = TypeVar("TypeLinkSequence", bound="LinkSequence") class FastAccessIOSequence(variabletools.FastAccess): @@ -539,11 +539,11 @@ def __init__( def __prepare_subseqs( self, - default: Type[ModelSequencesType], - class_: Optional[Type[ModelSequencesType]], + default: Type[TypeModelSequences], + class_: Optional[Type[TypeModelSequences]], cymodel, cythonmodule, - ) -> ModelSequencesType: + ) -> TypeModelSequences: name = default.__name__ if class_ is None: class_ = copy.copy(default) @@ -877,7 +877,7 @@ def __len__(self) -> int: class SubSequences( variabletools.SubVariables[ - SequencesType, SequenceType, variabletools.FastAccessType + TypeSequences, TypeSequence, variabletools.TypeFastAccess ], ): """Base class for handling subgroups of sequences. @@ -938,7 +938,7 @@ def name(self) -> str: class ModelSequences( - SubSequences[Sequences, ModelSequenceType, variabletools.FastAccessType], + SubSequences[Sequences, TypeModelSequence, variabletools.TypeFastAccess], ): """Base class for handling model-related subgroups of sequences.""" @@ -948,7 +948,7 @@ class ModelSequences( def __init__( self, master: Sequences, - cls_fastaccess: Optional[Type[variabletools.FastAccessType]] = None, + cls_fastaccess: Optional[Type[variabletools.TypeFastAccess]] = None, cymodel: Optional[CyModelProtocol] = None, ) -> None: self.seqs = master @@ -965,7 +965,7 @@ def __hydpy__initialise_fastaccess__(self) -> None: class IOSequences( - SubSequences[SequencesType, IOSequenceType, FastAccessIOSequenceType], + SubSequences[TypeSequences, TypeIOSequence, TypeFastAccessIOSequence], ): """Subclass of |SubSequences|, specialised for handling |IOSequence| objects.""" @@ -995,8 +995,8 @@ def save_series(self) -> None: class ModelIOSequences( - IOSequences[Sequences, ModelIOSequenceType, FastAccessIOSequenceType], - ModelSequences[ModelIOSequenceType, FastAccessIOSequenceType], + IOSequences[Sequences, TypeModelIOSequence, TypeFastAccessIOSequence], + ModelSequences[TypeModelIOSequence, TypeFastAccessIOSequence], ): """Base class for handling model-related subgroups of |IOSequence| objects.""" @@ -1021,7 +1021,7 @@ class InputSequences( class OutputSequences( ModelIOSequences[ - OutputSequenceType, + TypeOutputSequence, FastAccessOutputSequence, ], ): @@ -1120,7 +1120,7 @@ class AideSequences(ModelSequences["AideSequence", variabletools.FastAccess]): _CLS_FASTACCESS_PYTHON = variabletools.FastAccess -class LinkSequences(ModelSequences[LinkSequenceType, FastAccessLinkSequence]): +class LinkSequences(ModelSequences[TypeLinkSequence, FastAccessLinkSequence]): """Base class for handling |LinkSequence| objects.""" _CLS_FASTACCESS_PYTHON = FastAccessLinkSequence @@ -1142,7 +1142,7 @@ class SenderSequences(LinkSequences["SenderSequence"]): """Base class for handling "sender" |LinkSequence| objects.""" -class Sequence_(variabletools.Variable[SubSequencesType, variabletools.FastAccessType]): +class Sequence_(variabletools.Variable[TypeSubSequences, variabletools.TypeFastAccess]): """Base class for defining different kinds of sequences. Note that model developers should not derive their model-specific sequence classes @@ -1197,7 +1197,7 @@ class Sequence_(variabletools.Variable[SubSequencesType, variabletools.FastAcces strict_valuehandling: bool = False @property - def subseqs(self) -> SubSequencesType: + def subseqs(self) -> TypeSubSequences: """Alias for attribute |Variable.subvars|.""" return self.subvars @@ -1280,7 +1280,7 @@ def __repr__(self) -> str: return variabletools.to_repr(self, self.value, brackets) -class IOSequence(Sequence_[IOSequencesType, FastAccessIOSequenceType]): +class IOSequence(Sequence_[TypeIOSequences, TypeFastAccessIOSequence]): """Base class for sequences with input/output functionalities. The documentation on modules |filetools| and |netcdftools| in some detail explains @@ -2629,7 +2629,7 @@ def descr_device(self) -> str: class ModelSequence( - Sequence_[ModelSequencesType, variabletools.FastAccessType], + Sequence_[TypeModelSequences, variabletools.TypeFastAccess], ): """Base class for sequences to be handled by |Model| objects.""" @@ -2682,8 +2682,8 @@ def descr_device(self) -> str: class ModelIOSequence( - ModelSequence[ModelIOSequencesType, FastAccessIOSequenceType], - IOSequence[ModelIOSequencesType, FastAccessIOSequenceType], + ModelSequence[TypeModelIOSequences, TypeFastAccessIOSequence], + IOSequence[TypeModelIOSequences, TypeFastAccessIOSequence], ): """Base class for sequences with time-series functionalities to be handled by |Model| objects.""" @@ -2799,7 +2799,7 @@ def inputflag(self) -> bool: return self._get_fastaccessattribute("inputflag") -class OutputSequence(ModelIOSequence[OutputSequencesType, FastAccessOutputSequence]): +class OutputSequence(ModelIOSequence[TypeOutputSequences, FastAccessOutputSequence]): """Base class for |FactorSequence|, |FluxSequence| and |StateSequence|. |OutputSequence| subclasses implement an optional output mechanism. Generally, as @@ -2933,7 +2933,7 @@ def outputflag(self) -> bool: return self._get_fastaccessattribute("outputflag") -class DependentSequence(OutputSequence[OutputSequencesType]): +class DependentSequence(OutputSequence[TypeOutputSequences]): """Base class for |FactorSequence| and |FluxSequence|.""" def _finalise_connections(self) -> None: @@ -3001,7 +3001,7 @@ class FluxSequence(DependentSequence[FluxSequences]): class ConditionSequence( - ModelSequence[ModelSequencesType, variabletools.FastAccessType] + ModelSequence[TypeModelSequences, variabletools.TypeFastAccess] ): """Base class for |StateSequence| and |LogSequence|. @@ -3375,7 +3375,7 @@ class AideSequence(ModelSequence[AideSequences, variabletools.FastAccess]): _CLS_FASTACCESS_PYTHON = variabletools.FastAccess -class LinkSequence(ModelSequence[LinkSequencesType, FastAccessLinkSequence]): +class LinkSequence(ModelSequence[TypeLinkSequences, FastAccessLinkSequence]): """Base class for link sequences of |Model| objects. |LinkSequence| objects do not handle values themselves. Instead, they point to the diff --git a/hydpy/core/testtools.py b/hydpy/core/testtools.py index 15c47c8316..2fafdd5c90 100644 --- a/hydpy/core/testtools.py +++ b/hydpy/core/testtools.py @@ -404,9 +404,8 @@ class Test: def raw_first_col_strings(self) -> List[str]: """To be implemented by the subclasses of |Test|.""" - @staticmethod @abc.abstractmethod - def get_output_array(parseqs): + def get_output_array(self, parseqs): """To be implemented by the subclasses of |Test|.""" @property @@ -732,10 +731,8 @@ def dateformat(self, dateformat: str) -> None: ) from exc vars(self)["dateformat"] = dateformat - @staticmethod - def get_output_array(parseqs): - """Return the array containing the output results of the given - sequence.""" + def get_output_array(self, parseqs): + """Return the array containing the output results of the given sequence.""" return parseqs.series def prepare_node_sequences(self): diff --git a/hydpy/core/timetools.py b/hydpy/core/timetools.py index 962382008c..9d448a3114 100644 --- a/hydpy/core/timetools.py +++ b/hydpy/core/timetools.py @@ -34,7 +34,7 @@ TypeDate = TypeVar("TypeDate", bound="Date") TypePeriod = TypeVar("TypePeriod", bound="Period") TypeTimegrid = TypeVar("TypeTimegrid", bound="Timegrid") -TypeTOY = TypeVar("TypeTOY", bound="TOY") +TypeTOY = TypeVar("TypeTOY", bound="TOY") # pylint: disable=invalid-name TypeUnit = Literal["days", "d", "hours", "h", "minutes", "m", "seconds", "s"] diff --git a/hydpy/core/variabletools.py b/hydpy/core/variabletools.py index 05af63ba4c..136b0e9d7f 100644 --- a/hydpy/core/variabletools.py +++ b/hydpy/core/variabletools.py @@ -35,24 +35,15 @@ from hydpy.cythons.autogen import sequenceutils -GroupType = TypeVar( - "GroupType", +TypeGroup = TypeVar( + "TypeGroup", "parametertools.Parameters", "sequencetools.Sequences", "devicetools.Node", ) -SubVariablesType = TypeVar( - "SubVariablesType", - bound="SubVariables", -) -VariableType = TypeVar( - "VariableType", - bound="Variable", -) -FastAccessType = TypeVar( - "FastAccessType", - bound="FastAccess", -) +TypeSubVariables = TypeVar("TypeSubVariables", bound="SubVariables") +TypeVariable = TypeVar("TypeVariable", bound="Variable") +TypeFastAccess = TypeVar("TypeFastAccess", bound="FastAccess") INT_NAN: int = -999999 """Surrogate for `nan`, which is available for floating-point values but not for @@ -515,7 +506,7 @@ def __iter__(self): yield key -class Variable(Generic[SubVariablesType, FastAccessType]): +class Variable(Generic[TypeSubVariables, TypeFastAccess]): """Base class for |Parameter| and |Sequence_|. The subclasses are required to provide the class attributes `NDIM` @@ -1004,7 +995,7 @@ class Variable(Generic[SubVariablesType, FastAccessType]): INIT: Union[int, float, bool, None] = None NOT_DEEPCOPYABLE_MEMBERS: Tuple[str, ...] = ("subvars", "fastaccess") - _CLS_FASTACCESS_PYTHON: ClassVar[Type[FastAccessType]] + _CLS_FASTACCESS_PYTHON: ClassVar[Type[TypeFastAccess]] strict_valuehandling: bool = True @@ -1012,12 +1003,12 @@ class Variable(Generic[SubVariablesType, FastAccessType]): name: str unit: str - fastaccess: FastAccessType - subvars: SubVariablesType + fastaccess: TypeFastAccess + subvars: TypeSubVariables mask = masktools.DefaultMask() - def __init__(self, subvars: SubVariablesType): + def __init__(self, subvars: TypeSubVariables): self.subvars = subvars self.fastaccess = self._CLS_FASTACCESS_PYTHON() self.__valueready = False @@ -2137,21 +2128,21 @@ def __hydpy__set_shape__(self, shape: Tuple[int, ...]) -> NoReturn: @overload def sort_variables( - values: Iterable[Type[VariableType]], -) -> Tuple[Type[VariableType], ...]: + values: Iterable[Type[TypeVariable]], +) -> Tuple[Type[TypeVariable], ...]: ... @overload def sort_variables( - values: Iterable[Tuple[Type[VariableType], T]], -) -> Tuple[Tuple[Type[VariableType], T], ...]: + values: Iterable[Tuple[Type[TypeVariable], T]], +) -> Tuple[Tuple[Type[TypeVariable], T], ...]: ... def sort_variables( - values: Iterable[Union[Type[VariableType], Tuple[Type[VariableType], T]]] -) -> Tuple[Union[Type[VariableType], Tuple[Type[VariableType], T]], ...]: + values: Iterable[Union[Type[TypeVariable], Tuple[Type[TypeVariable], T]]] +) -> Tuple[Union[Type[TypeVariable], Tuple[Type[TypeVariable], T]], ...]: """Sort the given |Variable| subclasses by their initialisation order. When defined in one module, the initialisation order corresponds to the order @@ -2200,7 +2191,7 @@ def sort_variables( return tuple(value for _, value in sorted(counter_value)) -class SubVariables(Generic[GroupType, VariableType, FastAccessType]): +class SubVariables(Generic[TypeGroup, TypeVariable, TypeFastAccess]): """Base class for |SubParameters| and |SubSequences|. Each subclass of class |SubVariables| is thought for handling a certain group of @@ -2302,17 +2293,17 @@ class SubVariables(Generic[GroupType, VariableType, FastAccessType]): 1 """ - CLASSES: Tuple[Type[VariableType], ...] - vars: GroupType - _name2variable: Dict[str, VariableType] = {} - fastaccess: FastAccessType - _cls_fastaccess: Optional[Type[FastAccessType]] = None - _CLS_FASTACCESS_PYTHON: ClassVar[Type[FastAccessType]] + CLASSES: Tuple[Type[TypeVariable], ...] + vars: TypeGroup + _name2variable: Dict[str, TypeVariable] = {} + fastaccess: TypeFastAccess + _cls_fastaccess: Optional[Type[TypeFastAccess]] = None + _CLS_FASTACCESS_PYTHON: ClassVar[Type[TypeFastAccess]] def __init__( - self: SubVariablesType, - master: GroupType, - cls_fastaccess: Optional[Type[FastAccessType]] = None, + self: TypeSubVariables, + master: TypeGroup, + cls_fastaccess: Optional[Type[TypeFastAccess]] = None, ): self.vars = master if cls_fastaccess: @@ -2337,7 +2328,7 @@ def __hydpy__initialise_fastaccess__(self) -> None: else: self.fastaccess = self._cls_fastaccess() - def __getitem__(self, item) -> VariableType: + def __getitem__(self, item) -> TypeVariable: try: return self._name2variable[item] except KeyError: @@ -2346,7 +2337,7 @@ def __getitem__(self, item) -> VariableType: f"does not handle a variable named `{item}`." ) from None - def __getattr__(self, name) -> VariableType: + def __getattr__(self, name) -> TypeVariable: try: return self._name2variable[name] except KeyError: @@ -2363,7 +2354,7 @@ def __setattr__(self, name, value): else: variable.__hydpy__set_value__(value) - def __iter__(self) -> Iterator[VariableType]: + def __iter__(self) -> Iterator[TypeVariable]: for variable in self._name2variable.values(): yield variable