Open andeaseme opened 1 year ago
Thanks @andeaseme -- will look into it. What python version do you use?
I ask, because I wonder if it has to do with this 3.10... "bug".
There, you'll see, that it's functools.wraps
and staticmethod
that suddenly stopped working together.
Nope -- apparently it also doesn't work in 3.8 (pushed your test to dol
and CI validation (only 3.8 at this point) breaks: https://github.com/i2mint/dol/actions/runs/4063630336/jobs/6996091544#step:7:280
In fact, it has nothing to do with staticmethod
and classmethod
it seems. Even if you stick a normal method in there you stick in there will lead to the same error.
Updated issue name and content, as well as dol test, to reflect this.
To debug, follow the vine down this line of dol.base.Store
:
wrap = classmethod(partial(delegator_wrap, delegation_attr='store'))
Easier (and closer to the problem) test code, explain more of the context.
What does Store.wrap do? It wraps classes or instances in such a way that
mapping methods (like __iter__, __getitem__, __setitem__, __delitem__
, etc.)
are intercepted and transformed, but other methods are not (they stay as they
were).
This test is about the "stay as they were" part, so let's start with a simple class that has a method that we want to keep untouched.
class K:
def pass_through(self):
return 'hi'
def pass_through(self):
return 'hi'
return 'hi'
wrapping an instance
instance_of_k = K()
assert instance_of_k.pass_through() == 'hi'
wrapped_instance_of_k = Store.wrap(instance_of_k)
assert wrapped_instance_of_k.pass_through() == 'hi'
wrapping a class
WrappedK = Store.wrap(K)
instance_of_wrapped_k = WrappedK()
assert instance_of_wrapped_k.pass_through() == 'hi'
Everything seems fine, but the problem creeps up when we try to use these methods
assert K.pass_through(K()) == 'hi'
But this gives us an error on the wrapped class
assert WrappedK.pass_through(WrappedK()) == 'hi' # error
or even this:
assert WrappedK.pass_through(K()) == 'hi' # error
dol.base.Store.wrap
breaks unbound method calls.What's an "unbound method call"? See this Essentially, when you call
Klass.method(...)
(whether method is a normal, class, or static)See more of the context and easier to test code here.
_Note: The original issue was entitled "Adding wrap_kvs...", but changed this because the root cause is
dol.base.Store.wrap
, notwrap_kvs
itself._Test code:
Output: