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
Extract args from operator.attrgetter("xxx")
#113322
Comments
FWIW, it's currently possible to recover the args from an >>> operator.attrgetter('a').__reduce__()
(<class 'operator.attrgetter'>, ('a',))
>>> operator.attrgetter('a', 'b').__reduce__()
(<class 'operator.attrgetter'>, ('a', 'b')) |
Oh, that's what I was looking for. Seems a little hacky but fine enough. Sorry for the noise |
That does work, but |
You're right. Let's reopen this then. |
Why do you need this? |
I'm working on a config system based on https://github.com/google/ml_collections. They have a system of lazy-reference ( I would like to serialize to json the f1 = ml_collections.FieldReference()
f2 = f1.some_attribute
assert f2._ops = operator.attrgetter('some_attribute')
assert serialize_ref(f2) == {
'id': 1234,
'ops': {
'op_name': 'operator.attrgetter',
'arg': 'some_attribute',
},
} I'm sure if this was designed from scratch, there would be better way to handle this but I don't really have time to redesign the |
When you implement more or less general serialization protocol, it is common to use the parts of the pickle protocol. Now, if in future we add support of keyword arguments in So, while using |
Feature or enhancement
Proposal:
Given a
operator.attrgetter
instance, I would like to recover which attribute will be accessed. Something like:After inspecting the object, it doesn't seems possible to recover the argument passed:
Currently hack includes parsing
repr(op)
or applyingop(my_dummy_obj)
to a custom object which store the__getattr__
access.Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
The text was updated successfully, but these errors were encountered: