3232import re
3333import sys
3434from enum import Enum
35+ from typing import Dict
3536
3637from ansys .dpf .core .misc import module_exists
3738from ansys .dpf .gate .common import locations , ProgressBarBase # noqa: F401
@@ -433,7 +434,7 @@ def type_to_special_dpf_constructors():
433434_derived_class_name_to_type = None
434435
435436
436- def derived_class_name_to_type () -> dict [str , type ]:
437+ def derived_class_name_to_type () -> Dict [str , type ]:
437438 """
438439 Returns a mapping of derived class names to their corresponding Python classes.
439440
@@ -451,6 +452,30 @@ def derived_class_name_to_type() -> dict[str, type]:
451452 return _derived_class_name_to_type
452453
453454
455+ def record_derived_class (class_name : str , py_class : type , overwrite : bool = False ):
456+ """
457+ Records a new derived class in the mapping of class names to their corresponding Python classes.
458+
459+ This function updates the global dictionary that maps derived class names (str) to their corresponding
460+ Python class objects (type). If the provided class name already exists in the dictionary, it will either
461+ overwrite the existing mapping or leave it unchanged based on the `overwrite` flag.
462+
463+ Parameters
464+ ----------
465+ class_name : str
466+ The name of the derived class to be recorded.
467+ py_class : type
468+ The Python class type corresponding to the derived class.
469+ overwrite : bool, optional
470+ A flag indicating whether to overwrite an existing entry for the `class_name`.
471+ If `True`, the entry will be overwritten. If `False` (default), the entry will
472+ not be overwritten if it already exists.
473+ """
474+ recorded_classes = derived_class_name_to_type ()
475+ if overwrite or class_name not in recorded_classes :
476+ recorded_classes [class_name ] = py_class
477+
478+
454479def create_dpf_instance (type , internal_obj , server ):
455480 spe_constructors = type_to_special_dpf_constructors ()
456481 if type in spe_constructors :
0 commit comments