model.base: add id_short path resolution#249
Conversation
Resolution of id_short paths is added via `UniqueIdShortNamespace.get_referable()`, such that it can be used on every object, that spans such a namespace. `ModelReference.resolve()` is simplified to make use of this new functionality. Furthermore, tests for this are added.
Show the object, where the resolution failed, in the error messages.
A duplicate test is replaced by this test.
| item = UniqueIdShortNamespace.get_referable(item, # type: ignore[arg-type] | ||
| map(lambda k: k.value, self.key[1:])) |
There was a problem hiding this comment.
This is very elegant but indeed really hard to understand.
There was a problem hiding this comment.
I think the map(lambda... expression is pretty clean, but calling get_referable() and manually supplying self as item, because item is not necessarily a UniqueIdShortNamespace, is not. However, I think it's acceptable because get_referable() checks the type of self in the first iteration and because it's all documented via comments, in ModelReference.resolve() as well as UniqueIdShortNamespace.get_referable(). It's the only solution I could come up with that doesn't require duplicate error messages, i.e. having the same check with the same error message in both functions.
|
Other than that, this looks good to me! |
Resolution of id_short paths is added via
UniqueIdShortNamespace.get_referable(), such that it can be used on every object, that spans such a namespace.ModelReference.resolve()is simplified to make use of this new functionality. Furthermore, tests for this are added.Fix #214