Skip to content

Commit

Permalink
fix: staticmethod transforms only ran on the first time
Browse files Browse the repository at this point in the history
  • Loading branch information
blepabyte committed Sep 24, 2024
1 parent 8275f8a commit eae0fe9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
2 changes: 1 addition & 1 deletion maxray/function_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def validate(
)
else:
try:
fn._MAXRAY_TRANSFORM_ID = fd.compile_id
fn._PRE_MAXRAY_TRANSFORM_ID = fd.compile_id
fd.id_setattr_ok = True
except AttributeError:
fd.id_setattr_ok = False
Expand Down
33 changes: 31 additions & 2 deletions tests/test_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,8 +673,8 @@ def func():

func()

assert f1._MAXRAY_TRANSFORM_ID == f1_id
assert f2._MAXRAY_TRANSFORM_ID == f2_id
assert f1._PRE_MAXRAY_TRANSFORM_ID == f1_id
assert f2._PRE_MAXRAY_TRANSFORM_ID == f2_id
assert f1_id != f2_id


Expand Down Expand Up @@ -742,3 +742,32 @@ def get_prop():
return B().a_prop

assert get_prop() == 101


def test_staticmethod_patched():
class C:
@staticmethod
def foo():
return "a"

def bar(self):
return "f"

@maxray(lambda x, ctx: f"{x}{x}" if isinstance(x, str) else x)
def call_foo():
c1 = C.foo()
c2 = C.foo()
return c1, c2

@maxray(lambda x, ctx: f"{x}{x}" if isinstance(x, str) else x)
def call_bar():
c = C()
c1 = c.bar()
c2 = c.bar()
return c1, c2

c1, c2 = call_foo()
assert c1 == c2

b1, b2 = call_bar()
assert b1 == b2

0 comments on commit eae0fe9

Please sign in to comment.