Closed lululaplap closed 6 months ago
@mahmoud Would a PR implementing the above be welcome? Cheers
Oh interesting, I see what you're saying. So, you don't have control over the __getattr__
to, e.g., return None
if __getattr__
is called with glomit
as a name
?
I ask because dir()
isn't cheap or even authoritative in my experience. It's more like a help()
output than something on which one might base a protocol.
Assuming you don't, but do have access to the glom.assign
call, I think the best thing would be to wrap the val
in a Val
spec, like so:
...
obj = MyObject()
my_dict = glom.assign(obj={'a': 1}, path='a', val=Val(obj)) # added Val
a = glom.glom(my_dict, "a")
a.hello
# gets 'world'
What do you think?
I think the couple of solutions outlined here should address this issue. Feel free to reopen if they don't work for some reason.
Hello,
I have a dictionary which I am trying to assign values to using glom. Some of the objects I am using have the
__setattr__
dunder set to return acallable
by default. As suchglom
falsely believes it has the attributeglomit
and assigns the path to the result of the callable which__setattr__
returns. I have produced a minimal example belowproduces
I believe checking that the attribute is callable and is defined on the
dir
would solve this:Cheers, Lewis