Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This works this way:
The solver starts by trying to access the name as an attribute.
If an
AttributeError
exception is raised, then it tries to access itvia a dict-like approach.
If it still fail via a
KeyError
exception, then aAttributeNotFound
excetption is raised.The key must of course be one of the attribute allowed for the class.
Their is no way to specify keys to retrieve for a simple dict. If the
dict
class is added as a source to the registry allowing allattributes, then all keys will be allowed for all dicts (if the dict class is not registered as a source, no key will be available for simple dicts)
It still possible, though, to use a function at the upper level that
will act as an attribute and will return only some keys we want.
If we have this:
Then the user will be able to access
func
, thenfoo
bar
andbaz
from the dict.
If we don't want the user to access
baz
without modifying the class,we can do this:
Then, when solving the
func
attribute, it's thefunc
function whatwill be called, itself calling the method then returning a dict with
only the wanted keys
Another way to do it is: