-
Notifications
You must be signed in to change notification settings - Fork 2
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
wrap_kvs
inconsistencies (due to incorrect signature-based conditioning)
#9
Comments
Another example: from dol import Files, wrap_kvs, Pipe, filt_iter
from py2store import DirReader
rootdir = '/Users/Thor.Whalen/tmp/wikis/' # use any folder that contains git cloned packages
wrapper = wrap_kvs(obj_of_data=filt_iter(filt=lambda x: not x.split('/')[-2].startswith('.')))
MyStore = Pipe(DirReader, wrapper))
s = MyStore(rootdir)
list(s) # works
# but this fails:
v = s[next(iter(s))]
Replace the wrapper with: wrapper = wrap_kvs(obj_of_data=lambda v: filt_iter(v, filt=lambda x: not x.split('/')[-2].startswith('.'))) and it will work though. So obviously something to do with the signature of |
wrap_kvs(...obj_of_data)
inconsistency.wrap_kvs
inconsistencies (due to incorrect signature-based conditioning)
Another problem with First, let's reproduce the problem. The following works: import dol, recode
# The folder I used, here: https://www.dropbox.com/sh/q61xgnce0br7udd/AABOYefWcHjnaygTfZFvs2Ofa?dl=0
# if you have graze, you can get it with:
# import graze
# url = 'https://www.dropbox.com/sh/q61xgnce0br7udd/AABOYefWcHjnaygTfZFvs2Ofa?dl=0'
# graze.graze(url);
# path = graze.url_to_filepath(url)
path = '/Users/thorwhalen/graze/https/www.dropbox.com_f/sh_f/q61xgnce0br7udd_f/AABOYefWcHjnaygTfZFvs2Ofa?dl=0'
s = dol.FilesOfZip(path)
codec = recode.mk_codec('h')
trans = dol.wrap_kvs(
obj_of_data=lambda x: codec.decode(x),
data_of_obj=lambda x: codec.encode(x)
)
# trans = dol.kv_wrap(w)
ZippedPcms = trans(dol.FilesOfZip)
s = ZippedPcms(path)
k, v = s.head()
assert isinstance(next(iter(s.values())), list) But if you replace the trans = dol.wrap_kvs(
obj_of_data=codec.decode,
data_of_obj=codec.encode
) you get a AttributeError: type object 'type' has no attribute 'chk_format' The "how to use def _wrap_outcoming(
store_cls: type, wrapped_method: str, trans_func: Optional[callable] = None
):
if trans_func is not None:
wrapped_func = getattr(store_cls, wrapped_method)
if not _has_unbound_self(trans_func):
@wraps(wrapped_func)
def new_method(self, x):
return trans_func(getattr(super(store_cls, self), wrapped_method)(x))
else:
@wraps(wrapped_func)
def new_method(self, x):
return trans_func(
self, getattr(super(store_cls, self), wrapped_method)(x)
)
setattr(store_cls, wrapped_method, new_method) The idea is, if the One way is to engineer our condition better. Another, that I would favor at this point, is to ask the user to mark the least frequent case (I believe it's the "include the store instance" case) explicitly. For example, by wrapping it in a class, such as if not isinstance(trans_func, IncludeStoreInCall):
...
else:
trans_func = IncludeStoreInCall.trans_func
... The only reason I'm not implementing this now is that this would be a breaking change, so we'd need to figure out how to handle this change, search for usages in other packages, write some tests, and refactor where needed. |
And example of the problem with
wrap_kvs(...obj_of_data)
.But, though
bytes.decode
is "equivalent" tolambda x: bytes.decode(x)
, the following doesn't work:Instead we get:
The reason is that there's some dark (and apparently bad) magic happening behind the scenes.
Probably something that checks the signature of
obj_of_data
and does something (not so) "smart" about how it applies the function.┆Issue is synchronized with this Asana task by Unito
The text was updated successfully, but these errors were encountered: