Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bound partial for python 3.10 #3101

Merged
merged 6 commits into from
Jun 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pyro/poutine/messenger.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ class _bound_partial(partial):
support class methods as arguments to handlers.
"""

# Use '__slots__' for func to avoid the issue
# `_bound_partial(_bound_partial(f)).func is f`
# in Python 3.10.
__slots__ = "func"

def __init__(self, func):
self.func = func

def __get__(self, instance, owner):
if instance is None:
return self
Expand Down
10 changes: 10 additions & 0 deletions tests/poutine/test_poutines.py
Original file line number Diff line number Diff line change
Expand Up @@ -968,3 +968,13 @@ def model():

with poutine.mask(mask=False):
model()


def test_block_class_method():
class A:
@poutine.block
def run(self):
return 1

a = A()
a.run()