
Do you know what helps readability? *Learning to read*
Do you know what helps? *leveraging intuition* If you're going to throw a question mark in there, which by the way, is far more visually intrusive than a '.', then it makes more sense to at least try to use it in a familiar way: v = (a.b)? ## equivalent to v = None try: v = a.b except AttributeError as e: if not e.args[0].startswith("'NonezType'"): raise e Once you have learned to read ?. and friends, they will be as readable as .
and slicing is now.
That's an assumption that's difficult to prove. If ?. gets added to Python and proves to be a readability nightmare (as I believe it will be), it's too late to go back. It's a gamble. The question is: is the potential benefit worth the risk? and is there, perhaps, a better solution? I, personally am not convinced of either. I think the 'maybe' solution seems like a better alternative. On Wed, Jul 25, 2018 at 9:40 PM, Chris Angelico <rosuav@gmail.com> wrote:
On Thu, Jul 26, 2018 at 12:30 PM, David Mertz <mertz@gnosis.cx> wrote:
Btw. Here's a way of spelling the proposed syntax that gets the semantics right:
# pip install coalescing NullCoalesce(spam).eggs.bacon
Let's try it.
rosuav@sikorsky:~$ sudo python3 -m pip install coalescing Collecting coalescing Downloading https://files.pythonhosted.org/packages/f3/f4/ 120f04cc59f9fa8c55c711b67f1c9c34d8a59c34cd69249e6ff61b098987 /coalescing-0.1.1.tar.gz Installing collected packages: coalescing Running setup.py install for coalescing ... done Successfully installed coalescing-0.1.1
rosuav@sikorsky:~$ python3 Python 3.8.0a0 (heads/literal_eval-exception:ddcb2eb331, Feb 21 2018, 04:32:23) [GCC 6.3.0 20170516] on linux Type "help", "copyright", "credits" or "license" for more information.
from coalescing import NullCoalesce Traceback (most recent call last): File "<stdin>", line 1, in <module> ModuleNotFoundError: No module named 'coalescing' from coalesce import NullCoalesce Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python3.8/site-packages/coalesce.py", line 56, in <module> import wrapt ModuleNotFoundError: No module named 'wrapt'
A bit problematic. But after (a) figuring out that your module is named "coalesce" even though I installed "coalescing" AND (b) going and separately installing wrapt, and finally (c) doing the import that you didn't mention, we still have this fundamental problem:
rosuav@sikorsky:~$ python3 Python 3.8.0a0 (heads/literal_eval-exception:ddcb2eb331, Feb 21 2018, 04:32:23) [GCC 6.3.0 20170516] on linux Type "help", "copyright", "credits" or "license" for more information.
from coalesce import NullCoalesce from types import SimpleNamespace spam, spam.eggs, spam.eggs.bacon = SimpleNamespace(), SimpleNamespace(), 42 NullCoalesce(spam).eggs.bacon <NullCoalesce proxy for 42>
That isn't 42. That's a thing that, forever afterwards, will be a proxy. And look at this:
spam.nil = None print(NullCoalesce(spam).nil) <NullCoalesce proxy for None> print(NullCoalesce(spam).nil.nil) None print(NullCoalesce(spam).nil.nil.nil) Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'nil'
Whoooooops.
So, no, this is most definitely NOT equivalent to the proposed semantics.
ChrisA _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/