Conversation
|
|
|
What do you mean (I also need to check for |
|
What you want to test is 'does this object have a trait called name?', right? The snippet I posted should do that, though I haven't tested it. It seems preferable to me to do that test explicitly rather than asking for metadata to test if a trait exists. If this is a common enough case, we could have a |
|
We currently have a filter What I am testing is if the trait_metadata 'bar' for 'name' is True. If 'name' is not a trait at all, I want False, not an exception. It should be equivalent to |
|
OK. So that's implicitly I'm wary of making dynamic things too easy, because in the major use cases for traitlets, they are relatively static things which are defined by the class. Also, if we do this, I think the parameter name should be clearer. I'll have a think about what name I'd want. |
|
Ok, I think that it is fine. Did no think of the |
|
That doesn't actually exist, I was doing pseudocode ;-). But it's an easy addition if you think it's necessary. |
|
Well, that might be the reason :) opening a PR. |
If
allow_raiseis set toFalse, the methodtrait_metadatawill return the default value even iftraitnameis not a valid trait name.The goal is to optimize things like
which creates a dictionary and then checks if
nameis in it. Now one can simply do