allow from_string to be specified via metadata#624
allow from_string to be specified via metadata#624minrk wants to merge 1 commit intoipython:mainfrom
Conversation
avoids need to define custom Trait subclasses in order to register from_string
|
|
||
| # allow from_string to be overridden via metadata | ||
| if self.metadata.get("from_string"): | ||
| self.from_string = self.metadata["from_string"] |
There was a problem hiding this comment.
Why not look this up in the metadata dict rather than assign to an attr and find it there? Or if from_string can be a method on the class, use the metadata as a fallback. Seems like it would confusing or hard to debug if from_string in metadata were allowed to somewhat dynamically overwrite a method.
There was a problem hiding this comment.
Nevermind, given the point is to overwrite methods this makes sense.
There was a problem hiding this comment.
Yeah, it's the TraitType subclass priority I was thinking of. The alternative was to implement _from_string private method that does the lookup, but I thought that might get confusing.
|
I was about to merge this when I realized the argument should probably be a Bunch with access to the trait instance itself like we do with all other hooks, to grant access to other tags, default values, etc. |
|
Hm, but that makes it not have the same signature as the method. Maybe I should make the signature |
|
I think making it |
avoids need to define custom Trait subclasses just to define how strings are parsed, e.g.