On Mon, May 31, 2021 at 2:40 PM Guido van Rossum <gu...@python.org> wrote:

> Andre, did you have an experience where something related to Ellipsis/...
> confused you? It is not clear to me what exactly prompted you to single out
> Ellipsis (or it’s repr()?)
>

Guido, the reason why I tried is that I am working on a project called
friendly (previously named friendly-traceback) which aims to provide "easy
to understand" explanations to beginners when they encounter tracebacks.[1]

In playing with different cases involving assignments to a constant
(__debug__, None, True, False, ... and Ellipsis as '...'), I came across
this particular case which I thought was confusing: Python says that we
cannot assign to Ellipsis ... and yet we can.  I thought that the
explanation provided by cPython itself could be made a bit clearer.
The specific suggestion I made is based on the explanation *friendly*
currently gives, where it specifies that Ellipsis refers to (...).

Admittedly, this is rather a corner case.

André

====
With friendly, I usually strive to cover more typical cases that are
encountered by beginners, such as one example I gave at this year's PyConUS
Education summit where, given the following message:

AttributeError: partially initialized module 'turtle' has no attribute
'forward' (most likely due to a circular import)

friendly adds the following "hint":

Did you give your program the same name as a Python module?

And, upon being prompted, friendly adds the following:

I suspect that you used the name turtle.py for your program and that you
also wanted to import a
module with the same name from Python's standard library. If so, you should
use a different name for your program.

(This particular turtle is not hard-coded in friendly; any circular import
is similarly analyzed and some further explanation is provided.)

[1]  Currently, I have at least 150 different cases yielding SyntaxErrors
for which friendly can provide help (see
https://aroberge.github.io/friendly-traceback-docs/docs/html/syntax_tracebacks_en_3.8.html
for cases covered by unit tests) and probably a hundred or so of various
types of other errors. Furthermore, friendly is designed so that the
explanations can be translated into other languages; currently, every case
friendly covers has explanations available in both English and French.


> On Mon, May 31, 2021 at 08:37 André Roberge <andre.robe...@gmail.com>
> wrote:
>
>>
>>
>> On Mon, May 31, 2021 at 12:20 PM MRAB <pyt...@mrabarnett.plus.com> wrote:
>>
>>> On 2021-05-31 15:55, Paul Bryan wrote:
>>> > If you're proposing prevention of monkey patching Ellipsis, I think
>>> > you'll have to go all-in on all builtins.
>>> >
>>> > For example:
>>> >
>>> >>>> str = int
>>> >
>>> >>>> str
>>> >
>>> > <class 'int'>
>>> >
>>> >>>> str == int
>>> >
>>> > True
>>> >
>>> >
>>> If you rebind str to int, the repr of str will say <class 'int'>, so you
>>> can tell that something's happened, but the repr of ... is always
>>> 'Ellipsis', even though you've rebound Ellipsis.
>>>
>>
>> Exactly.
>>
>> Thinking some more about it, perhaps the confusion would be sufficiently
>> reduced if the repr of '...' would be 'Ellipsis (...)', and use this repr
>> to appear in error messages rather than simply the name Ellipsis.
>>
>>
>>
>>>
>>> >
>>> > On Mon, 2021-05-31 at 11:37 -0300, André Roberge wrote:
>>> >> In Python `...` is referred to as `Ellipsis` and cannot be assigned
>>> to.
>>> >> Yet, one can assign any value to the name `Ellipsis`.
>>> >>
>>> >> Consider the following:
>>> >>
>>> >> ```
>>> >> >>> ...
>>> >> Ellipsis
>>> >> >>> ... == Ellipsis
>>> >> True
>>> >> >>> Ellipsis
>>> >> Ellipsis
>>> >> >>> Ellipsis = 3
>>> >> >>> Ellipsis
>>> >> 3
>>> >> >>> ... = 4
>>> >>   File "<stdin>", line 1
>>> >>     ... = 4
>>> >>     ^
>>> >> SyntaxError: cannot assign to Ellipsis
>>> >> >>>  # But I just did assign a new value to the name Ellipsis above.
>>> >> >>> Ellipsis
>>> >> 3
>>> >> >>> ...
>>> >> Ellipsis
>>> >> >>> ... == Ellipsis
>>> >> False
>>> >> ```
>>> >>
>>> >> For consistency, `Ellipsis` (the name) should **always** refer to the
>>> >> same object that `...` refers to, so that both could not be assigned
>>> a
>>> >> new value.
>>> >>
>>> _______________________________________________
>>> 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/NE2FAW3XDFYUIMILV4BC2XT6VKLC4P6V/
>>> Code of Conduct: http://python.org/psf/codeofconduct/
>>>
>> _______________________________________________
>> 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/DIRDIQFK72LFHYJNAD5BWL3L5SPAUMVM/
>> Code of Conduct: http://python.org/psf/codeofconduct/
>>
> --
> --Guido (mobile)
>
_______________________________________________
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/VWKCMABYL3B4VMN22I7HYEYJOITUOQPV/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to