-
-
Notifications
You must be signed in to change notification settings - Fork 28
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
Arbitrary Python objects #32
Comments
Hello, sorry for the very slow response. You're correct at the moment this isn't possible. I wonder if (This problem is very related to #1 I think.) |
To deal with this in a current project, I've been using a proxy class that can wrap an object and make it look like a dict to class DictProxy(collections.abc.Mapping):
_inner = None
_keys = None
def __init__(self, inner, aliases=None):
self._aliases = aliases or {}
self._inner = inner
self._keys = [k for k in dir(inner) if not k.startswith("_")]
for alias in self._aliases:
if alias not in self._keys:
self._keys.append(alias)
def __getitem__(self, key):
if key in self._aliases:
alias = self._aliases[key]
if type(alias) is str:
return getattr(self._inner, self._aliases[key])
else:
return alias(self._inner)
elif key in self._keys:
return getattr(self._inner, key)
else:
raise KeyError
def __iter__(self):
yield from self._keys
def __len__(self):
return len(self._keys)
def __contains__(self, key):
return key in self._keys
def keys(self):
return list(self._keys) I only need to go in the Python -> Rust direction, but I think a similar approach could work in the other direction as well. One semi-major frustration at the moment, though: as currently implemented, the deserializer for mappings calls both It doesn't seem like there's any reason it has to work that way, but that's how it works now. I think if object deserialization were to be explicitly supported, some kind of laziness would be important. |
Given that pythonize doesn't yet support arbitrary python objects it is not as powerful as pickle which means that it doesn't have the same security concerns as pickle does. If you manage to support arbitrary python objects it's worth considering to leave a function that doesn't support the full set of python objects as that is a feature in of itself in terms of keeping security tight. |
I'm using dill (or pickle) to serialize any python object with a little code you can do a serde with module and it's work nice. |
Maybe this is totally off, but would it even be possible to support arbitrary Python objects? For example, if I had a Python function like this:
This crate is super convenient to parse and validate
type
,status_code
andmethod
since you can make a declarative serve model for this:But as far as I can tell there is no way to say "make the
callback
key aPy<PyAny>
. In other words, something like:Is that right?
The text was updated successfully, but these errors were encountered: