cwacek / python-jsonschema-objects

Automatic Python binding generation from JSON Schemas
MIT License
364 stars 96 forks source link

Feature Request: attribute descriptors change their reference when descriptor __set__ is called #225

Closed bdanofsky closed 1 year ago

bdanofsky commented 3 years ago

What are you trying to do? When a descriptor is of type ProtocolBase and a few other types the set method creates a value which changes the reference to the underlying object value. This causes the actual reference to the object to change in the parent class

Instead of deleting the old reference and replacing with new it would be good to iterate over the keys (in the case of ProtocolBase) and set each leaf node to the appropriate literal value.

In descriptor.set the last line of the method is obj._properties[self.prop] = val where val is a different type depending on the property type (i.e. self.info['type']) In the conditional in the body of the code there are several cases that basically do

val = self.info'typ' this remaps the input (literal) to the internal type. This object then replaces the instance of property object with the new instance. In my use case this causes problems since I need a mapping of objects that is relatively constant and hashable.

If you can give me some brief guidance on if and how you want this done I can implement the fix and issue the a pull request.

cwacek commented 1 year ago

Closing this very old issue. If still a fresh issue for anyone, shout.