MCPcopy
hub / github.com/ray-project/ray / _ray_from_modified_class

Method _ray_from_modified_class

python/ray/actor.py:1504–1570  ·  view source on GitHub ↗
(
        cls,
        modified_class,
        class_id,
        actor_options,
    )

Source from the content-addressed store, hash-verified

1502
1503 @classmethod
1504 def _ray_from_modified_class(
1505 cls,
1506 modified_class,
1507 class_id,
1508 actor_options,
1509 ):
1510 for attribute in [
1511 "remote",
1512 "_remote",
1513 "_ray_from_modified_class",
1514 "_ray_from_function_descriptor",
1515 ]:
1516 if hasattr(modified_class, attribute):
1517 logger.warning(
1518 "Creating an actor from class "
1519 f"{modified_class.__name__} overwrites "
1520 f"attribute {attribute} of that class"
1521 )
1522
1523 # Make sure the actor class we are constructing inherits from the
1524 # original class so it retains all class properties.
1525 class DerivedActorClass(cls, modified_class):
1526 def __init__(self, *args, **kwargs):
1527 try:
1528 cls.__init__(self, *args, **kwargs)
1529 except Exception as e:
1530 # Delegate call to modified_class.__init__ only
1531 # if the exception raised by cls.__init__ is
1532 # TypeError and not ActorClassInheritanceException(TypeError).
1533 # In all other cases proceed with raise e.
1534 if isinstance(e, TypeError) and not isinstance(
1535 e, ActorClassInheritanceException
1536 ):
1537 modified_class.__init__(self, *args, **kwargs)
1538 else:
1539 raise e
1540
1541 name = f"ActorClass({modified_class.__name__})"
1542 DerivedActorClass.__module__ = modified_class.__module__
1543 DerivedActorClass.__name__ = name
1544 DerivedActorClass.__qualname__ = name
1545 # Construct the base object.
1546 self = DerivedActorClass.__new__(DerivedActorClass)
1547 # Actor creation function descriptor.
1548 actor_creation_function_descriptor = PythonFunctionDescriptor.from_class(
1549 modified_class.__ray_actor_class__
1550 )
1551
1552 actor_method_meta = _ActorClassMethodMetadata.create(
1553 modified_class,
1554 actor_creation_function_descriptor,
1555 )
1556 self.__ray_metadata__ = _ActorClassMetadata(
1557 Language.PYTHON,
1558 modified_class,
1559 actor_creation_function_descriptor,
1560 class_id,
1561 actor_method_meta,

Callers 1

_make_actorFunction · 0.80

Calls 5

_ActorClassMetadataClass · 0.85
_process_option_dictFunction · 0.85
warningMethod · 0.45
__new__Method · 0.45
createMethod · 0.45

Tested by

no test coverage detected