Skip to content

Make HashablePartial work with partials (Pre Python 3.10)

Vicentini Filippo requested to merge github/fork/inailuig/partial into master

Created by: inailuig

previously HashablePartial would error when the function passed to it was a partial (< Python 3.10):

from functools import partial
from netket.jax import HashablePartial

def f(a, b, c):
    pass

g = partial(f, 2)
h = HashablePartial(g, 3)

h.__hash__()
AttributeError: 'functools.partial' object has no attribute '__code__'

This PR fixes this and adds the functionality that a functools.partial can be made hashable in terms of it's original args by wrapping it with a HashablePartial (< Python 3.10) i.e.

HashablePartial(partial(f, x)) == HashablePartial(f, x)

Merge request reports