mirror of
https://github.com/wassname/ray.git
synced 2026-07-17 11:32:33 +08:00
Treat static methods as class methods instead of instance methods in actors (#6756)
* Treat static methods as class methods rather than instance methods * Add tests for static methods in actors * Revert formatting changes * Readd future imports * Restructure static method check * Documentation enhancements * Fix linting issues
This commit is contained in:
committed by
Edward Oakes
parent
2e972e725a
commit
c480d1d1e4
@@ -208,6 +208,55 @@ def test_actor_class_attributes(ray_start_regular):
|
||||
assert ray.get(t.g.remote()) == 3
|
||||
|
||||
|
||||
def test_actor_static_attributes(ray_start_regular):
|
||||
class Grandparent:
|
||||
GRANDPARENT = 2
|
||||
|
||||
@staticmethod
|
||||
def grandparent_static():
|
||||
assert Grandparent.GRANDPARENT == 2
|
||||
return 1
|
||||
|
||||
class Parent1(Grandparent):
|
||||
PARENT1 = 6
|
||||
|
||||
@staticmethod
|
||||
def parent1_static():
|
||||
assert Parent1.PARENT1 == 6
|
||||
return 2
|
||||
|
||||
def parent1(self):
|
||||
assert Parent1.PARENT1 == 6
|
||||
|
||||
class Parent2:
|
||||
PARENT2 = 7
|
||||
|
||||
def parent2(self):
|
||||
assert Parent2.PARENT2 == 7
|
||||
|
||||
@ray.remote
|
||||
class TestActor(Parent1, Parent2):
|
||||
X = 3
|
||||
|
||||
@staticmethod
|
||||
def f():
|
||||
assert TestActor.GRANDPARENT == 2
|
||||
assert TestActor.PARENT1 == 6
|
||||
assert TestActor.PARENT2 == 7
|
||||
assert TestActor.X == 3
|
||||
return 4
|
||||
|
||||
def g(self):
|
||||
assert TestActor.GRANDPARENT == 2
|
||||
assert TestActor.PARENT1 == 6
|
||||
assert TestActor.PARENT2 == 7
|
||||
assert TestActor.f() == 4
|
||||
return TestActor.X
|
||||
|
||||
t = TestActor.remote()
|
||||
assert ray.get(t.g.remote()) == 3
|
||||
|
||||
|
||||
def test_caching_actors(shutdown_only):
|
||||
# Test defining actors before ray.init() has been called.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user