Search code examples
pythonactorpykka

Pykka: get the base class of an Actor


I use pykka python library. I would like to create an actor, and later test if the actor created is of the proper class.

class MyActor( ThreadingActor ):
  # ...

actor = MyActor.start().proxy()

assert actor.__class__ == MyActor # check here?

Here actor.__class__ is pykka.actor.ActorRef. How to check if it refers to MyActor class? I need it for a unit test suite.


Solution

  • To get the actor class from an pykka.actor.ActorRef:

    ref = MyActor.start()
    assert ref.actor_class == MyActor
    

    To get the actor class from an pykka.proxy.ActorProxy:

    proxy = MyActor.start().proxy()
    assert proxy.actor_ref.actor_class == MyActor
    

    I've forgotten to document the actor_class field on ActorRef objects, but all fields that are not made "private" by prefixing with underscore will continue to be supported in the future.