aliastools¶
This module provides tools for the efficient handling of input and output sequence aliases.
Module aliastools implements the following members:
LazyInOutSequenceImportImport the input or output sequence the alias is referring to only when required.
write_sequencealiases()Write the sequence alias module aliases.py.
- class hydpy.core.aliastools.LazyInOutSequenceImport(modulename: str, classname: str, alias: str, namespace: dict[str, Any])[source]¶
 Bases:
objectImport the input or output sequence the alias is referring to only when required.
Importing all input and output sequences costs a significant amount of initialisation time, and one typically uses at most a few of them within a specific project. Hence, we implemented class
LazyInOutSequenceImportfor postponing the imports of the sequences available by modules inputs and outputs. We hope we could catch all exceptional cases so that a user will never realise to work with aLazyInOutSequenceImportobject instead with an input or output class object (except when directly asking for it with functiontype).Directly after importing, the alias is of type
LazyInOutSequenceImport:>>> from hydpy.core.aliastools import LazyInOutSequenceImport >>> def get_example_alias(): ... return LazyInOutSequenceImport( ... modulename="hydpy.models.hland.hland_inputs", ... classname="T", ... alias="hland_inputs_T", ... namespace=locals(), ... ) >>> hland_inputs_T = get_example_alias() >>> type(hland_inputs_T) <class 'hydpy.core.aliastools.LazyInOutSequenceImport'>
After accessing an attribute, its type changed to
ABCMeta, which is the meta-class of all input and output sequences:>>> hland_inputs_T.__name__ 'T' >>> type(hland_inputs_T) <class 'type'>
Due to Python’s special method lookup, we must explicitly define the relevant ones. The following examples list all considered methods:
>>> hland_inputs_T = get_example_alias() >>> from hydpy.models.hland.hland_inputs import T, P >>> hash(hland_inputs_T) == hash(T) True
>>> hland_inputs_T = get_example_alias() >>> hland_inputs_T == T True >>> hland_inputs_T = get_example_alias() >>> T == hland_inputs_T True
>>> hland_inputs_T = get_example_alias() >>> hland_inputs_T != P True >>> hland_inputs_T = get_example_alias() >>> P != hland_inputs_T True
>>> hland_inputs_T = get_example_alias() >>> str(hland_inputs_T) "<class 'hydpy.models.hland.hland_inputs.T'>"
>>> hland_inputs_T = get_example_alias() >>> repr(hland_inputs_T) "<class 'hydpy.models.hland.hland_inputs.T'>"
>>> hland_inputs_T = get_example_alias() >>> dir(hland_inputs_T) ['INIT', 'NDIM', ...]
- hydpy.core.aliastools.write_sequencealiases() None[source]¶
 Write the sequence alias module aliases.py.
After extending a model or adding a new one, you can update the module by calling
write_sequencealiases():>>> from hydpy.core.aliastools import write_sequencealiases >>> write_sequencealiases()