On Fri, Oct 15, 2021 at 06:37:04PM -0400, Ricky Teachey wrote:

> You say a soft keyword isn't an option and I understand why, but what about
> one that is incredibly unlikely to have been used very often? I'm thinking
> of just a simple double underscore:
> 
> >>> a = __
> >>> a
> 'a'

I frequently use double underscore as a "don't care" name to avoid 
shadowing the single underscore, which has special meaning in the 
interactive interpreter as the previous result.

Jupyter and IPython use `__` for the second previous result, and `___` 
for the third previous result.


    In [10]: 2*6
    Out[10]: 12

    In [11]: 2*4
    Out[11]: 8

    In [12]: _ + __
    Out[12]: 20


It would be nice if somebody were to do a survey of other languages and 
see which ones, if any, provide this functionality and what token they 
use for it.

The token should preferably be:

* self-explanatory, not line-noise;

* shorter rather than longer, otherwise it is easier to just 
  type the target name as a string: 'x' is easier to type than
  NAME_OF_ASSIGNMENT_TARGET;

* backwards compatible, which means it can't be anything that
  is already a legal name or expression;

* doesn't look like an error or typo.

I don't think we can satisfy all four requirements, and I'm not entirely 
convinced that the use-cases are common or important enough to justify 
this feature if it only satisfies two or three of them.

Classes, functions, decorators and imports already satisfy the "low 
hanging fruit" for this functionality. My estimate is that well over 99% 
of the use-cases for this fall into just four examples, which are 
already satisfied by the interpreter:


    # like `math = __import__('math')`
    import math

    # like K = type('K', (), ns)
    class K(): ...

    # like func = types.FunctionType(code, globals, 
    #                 name='func', argdefs, closure)
    def func(): ...

    # like func = decorator(func)
    # similarly for classes
    @decorator
    def func(): ...


If we didn't already have interpreter support for these four cases, it 
would definitely be worth coming up with a solution. But the use-cases 
that remain are, I think, quite niche and uncommon.



-- 
Steve
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/YKZOGXJTNGZ3F3YCHE2GKPK44RRJ7H5N/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to