News for hackers. Stuff that matters.
Re:PEP 505: Bringing None-Aware Operators to Python by singularity2001 on Sunday August 12, 2018 @08:14AM (#17744017)
It can already be written nicely as

   libpaths = paths.split(":") if paths else []
Please don't adopt unnecessary sigil junk from other languages.
Re:PEP 505: Bringing None-Aware Operators to Python by culturedsystems on Sunday August 12, 2018 @09:52AM (#17744339)
I think a better example to show why you might want a ?. operator would involve nested lookups. If you have something like node.child.attribute.value, handling potential Nones at each lookup with ifs would get very verbose very quickly (and that verbosity would be bad, as it would make it much harder to make out the main point of the code).

You could surround the nested lookups in try/except and catch the AttributeError, but that could mask other errors - for instance, if you misspelled the name of one of the nested attributes (arguably, it would be better if trying to look up an attribute on None raised a different exception, rather than AttributeError).

Re:PEP 505: Bringing None-Aware Operators to Python by singularity2001 on Monday August 13, 2018 @03:23AM (#17748534)
I don't think the existing pythonic way is not too verbose:

   if node and node.child and node.child.attribute: 
      …
Re:PEP 505: Bringing None-Aware Operators to Python by singularity2001 on Monday August 13, 2018 @03:26AM (#17748546)
for nested loop you can do

   for child in node.children or []:
      for attrib in child.attributes or []:
         …
Re:PEP 505: Bringing None-Aware Operators to Python by Doxin on Monday August 13, 2018 @08:10AM (#17749444)
That's generally considered unpythonic though. A more pythonic way to write that is

    for child in node.children if node.children else []:
        for attrib in child.attributes if child.attributes else []:
            ...
Which, granted, is a lot more verbose and probably not any more readable but at least it's not abusing the or operator.
Re:PEP 505: Bringing None-Aware Operators to Python by pjz on Sunday August 12, 2018 @03:26PM (#17745985)
This is subtly incorrect. Correctly, it should be:

    libpaths = paths.split(":") if paths is not None else []
or else falsey values of paths (0, [], False) can still cause an error.
Re:PEP 505: Bringing None-Aware Operators to Python by singularity2001 on Monday August 13, 2018 @03:17AM (#17748517)
If your path variable is set to 0, [], False then it's best to fail early anyways.