New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
getitem of sections should treat props and sections identically. #240
Comments
I am myself no longer in the business of writing odML related code so I am staying out of this, and I do understand your argument, but I remember that I was the one pushing for this (and implementing it), mainly because I found working with odML very cumbersome and verbose, especially due to the multi-value support: just look at example in Java. This translated to python, with the least "implicit" as possible this would also look like |
I'm all for reducing ambiguity and I agree there's a bit of an issue here. With the harmonisation of odML and NIX that we're currently working towards, the support for multiple values will be dropped. So I think this will become a simpler issue to address then and it's not worth discussing how we want the current state to behave. So the question now becomes whether |
Once support for multiple values is dropped I think whether we should return So for option 1), I think we should everywhere only iterate on So for option 1 I think we should return I prefer option 1 since it's probably what most want by default, I think. I think the desire behind what lead to iterating over For more things to do, we have not talked about I can work on implementing these things when we agree on how it should be. Also, what's the timeline on dropping support for multiple properties (although I guess we don't have to wait for that)? |
There are some inconsistencies, I believe, in sections/properties.
When accessing an item from a section by key, e.g.
section['name']
, the returned value is treated differently depending whether the key is a property or a section as can be sen here.If it's a section, the section is returned. If it's a prop, if it's a single
Value
prop, thevalues[0].value
is returned, otherwise a theValue
's,values
are returned. It think in the zen of python that explicit is better than implicit, we shouldn't do that.At best, I think we should always return the
Value
's,values
, even if there's only one. We shouldn't guess that a single valued prop is different than multiple valued prop. Unless the underlying code will always treat a single value different than multiple values (i.e. ValueList and Value, although this seems like a bad idea).Or in my opinion, we should never return the
Value
's,values
, but rather theValue
itself. Just like we return theSection
if it's a section. This would even allow us to doif isinstance
on the returned value.When assigning to a section or property(?) we can do
section['name'] = 'stuff'
which creates a single valuedValue
, so I can see the desire to also return the first item of theValue
if there's only one. But I think users will be able to distinguish between allowing that assignment for ease of use, and always getting aValue
when doing getitem, especially if it's documented. On the flip side, guessing what the user wants will lead to confusion, even if documented.I believe that method should look as follows:
The text was updated successfully, but these errors were encountered: