traits icon indicating copy to clipboard operation
traits copied to clipboard

Add tests and docs for xgetattr and xsetattr

Open mdickinson opened this issue 3 years ago • 1 comments

From https://github.com/enthought/traits/issues/1239#issuecomment-657655412:

xgetattr should really get tests, a decent docstring, and arguably fixes, too: the current version does different things for intermediate lookups than for the final lookup, for no obvious reason: for intermediate lookups, an actual value of None is replaced with default. For the final lookup, a value of None is left as None.

mdickinson avatar Oct 23 '20 09:10 mdickinson

On the fixes front, it's hard to change behaviour here since external packages are already using xgetattr or xsetattr.

This may be a good opportunity to think again about the behaviour we actually want, particularly with respect to None-handling, missing attributes, and default values, and recodify it under a better name or in a better place.

If the intent is to support retrieval of values represented by extended trait names on a HasTraits class, one option may be a method on HasTraits. (That would preclude re-using the same logic for doing extended imports, but that's a different use-case, and seems like a misuse of xgetattr in the first place.)

mdickinson avatar Oct 23 '20 10:10 mdickinson