Prevent self-recursion on name fields implicitly#4
Conversation
name fieldsname fields implicitly
waltermwaniki
left a comment
There was a problem hiding this comment.
Also can't imagine a situation where one would want to inject an object into itself (not sure if this is even possible) - this update is very welcome I believe.
Perhaps unrelated to this request though, I think we should avoid using python reserved names/core module names. Maybe consider renaming the "class" attribute in config to something else like "target" or "driver". And renaming the device_spinner.builtins module to something else...
|
@waltermwaniki I'm open to changing it. The original (and still valid!) syntax is: module: <module path>
class: <class name>
args: ...
kwds: ...I like this syntax because it's consistent with Python. The What's shown in the first comment is the shortened syntax, which is a concatenation of If we want to rename these, here are some nuances to consider:
For the "builtins", maybe we could call it |
|
@Poofjunior I like using the term I can also see a case where we only have the factory key. it shouldn't matter if it is a class or a function since they're all |
|
@waltermwaniki I renamed the |
|
Self-recursion fix looks great! For the to_list addition, I believe that it's necessary, but could you add an example or something to document the kind of error you might see if you just use |
|
@patricklatimer I added the "gotcha" to the readme, along with a bit more documentation. (Docs are still a TODO.) |
Fixes #3
Added some syntactic sugar to prevent an instance from trying to recursively stuff an instance of itself into itself.
Previously, you had to mark the value to be skipped:
Now,
DeviceSpinnercan tell that you're not trying to instantiate an object by putting an instance of itself into itsellf recursively, so it skips args/kwarg-values that match the instance. (I can't think of any use case where this is desireable so we'll explicitly not-support it unless we have a good reason otherwise down the road.)Now you can do this without recursing forever:
Finally, because this packages supports creating devices using
__init__and also any function that returns an object, I added ato_list(*elements)function so that we can define an unbounded list in yamls. This is the only literal that needs to be handled this way.