Files
ResInsight/GrpcInterface/Python/rips/enums.py
T
Kristian Bendiksen 79914f2a00 #13982 Python: Type case API with StrEnum classes for proto enums
The previous commit auto-generated StrEnum classes for caf::AppEnum scriptable
fields, but the hand-written gRPC API in rips.case still accepted bare strings
for proto-backed enums (PropertyType, PropertyDataType, NNCPropertyType) and
the AppEnum-backed PorosityModelType.

Add a new rips.enums module with hand-written StrEnum classes for the three
proto-only enums and reuse the auto-generated PorosityModelType from
resinsight_classes. Re-export the new enums from the rips package and narrow
the parameter type hints across cell_count, cell_info_for_active_cells,
available_properties, active_cell_property, selected_cell_property,
grid_property, set_active_cell_property, set_grid_property,
active_cell_centers, active_cell_corners, set_nnc_connections_values, and
grid_property_for_positions (sync and async variants).

Existing string arguments keep working because StrEnum members are strings
and protobuf's EnumTypeWrapper.Value accepts both. A new
test_10k_grid_property_strenum asserts string and enum forms return the same
data.
2026-05-13 13:47:40 +02:00

43 lines
1.5 KiB
Python

"""Typed enums mirroring the proto enums used by the rips.case API.
These are hand-written counterparts to proto enums defined in ``Properties.proto``
and ``NNCProperties.proto``. They give users typed, autocompletable enum members
while remaining wire-compatible with the existing string-based API (``StrEnum``
members are strings).
Auto-generated ``StrEnum`` classes for ``caf::AppEnum`` scriptable fields live in
``rips.generated.generated_classes`` and are emitted by ``cafPdmPythonGenerator``.
``PorosityModelType`` is one of those auto-generated enums and is imported from
``resinsight_classes``; the enums in this module cover the gRPC-only proto enums
that the auto-generator does not see.
"""
from enum import StrEnum
# Keep in sync with PropertyType in GrpcInterface/GrpcProtos/Properties.proto
class PropertyType(StrEnum):
DYNAMIC_NATIVE = "DYNAMIC_NATIVE"
STATIC_NATIVE = "STATIC_NATIVE"
SOURSIMRL = "SOURSIMRL"
GENERATED = "GENERATED"
INPUT_PROPERTY = "INPUT_PROPERTY"
FORMATION_NAMES = "FORMATION_NAMES"
FLOW_DIAGNOSTICS = "FLOW_DIAGNOSTICS"
INJECTION_FLOODING = "INJECTION_FLOODING"
REMOVED = "REMOVED"
UNDEFINED = "UNDEFINED"
# Keep in sync with PropertyDataType in GrpcInterface/GrpcProtos/Properties.proto
class PropertyDataType(StrEnum):
FLOAT = "FLOAT"
INTEGER = "INTEGER"
# Keep in sync with NNCPropertyType in GrpcInterface/GrpcProtos/NNCProperties.proto
class NNCPropertyType(StrEnum):
NNC_DYNAMIC = "NNC_DYNAMIC"
NNC_STATIC = "NNC_STATIC"
NNC_GENERATED = "NNC_GENERATED"