[Python-ideas] PEP 505: None-aware operators

Grégory Lielens gregory.lielens at gmail.com
Mon Jul 23 08:46:31 EDT 2018


 Paul Moore wrote:
>
> This is my impression, as well. It seems like something that's helpful
> in dealing with unstructured object hierarchies with lots of optional
> attributes - which is where JSON tends to be used.
>
> But given that, I'm really much more interested in seeing the new
> operators compared against a well-written "JSON object hierarchy
> traversal" library than against raw Python code.
>

Good point, I did not think about that when suggesting to give some 
context, but indeed if it's linked to a library in particular, there is 
always the possibility to choose another object than None as the "nothing 
here" marker. 

One that will absorb getitems and  getattr accesses so that ?.  and ?[] 
behavior is reproduced by plain . and []. Guard/NoValues should be chosen 
so that typical lib use is easier. 


Anyway, addressing partially-populated nodes would need lib support: 
None-coalescence will not help when you traverse a dict/attribute hierarchy 
where some nodes implement some attributes/keys but not others. It help 
only when a node is either regular, or a guard object without any 
attributes...So an irregular tree, but not too irregular ;-)... 


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180723/0366b983/attachment.html>


More information about the Python-ideas mailing list