[Python-3000] Ellipsis

Thomas Wouters thomas at python.org
Fri Jan 25 00:38:29 CET 2008


On Jan 24, 2008 3:25 PM, James Thiele <python3now at gmail.com> wrote:

> On Jan 24, 2008 1:14 PM, Christian Heimes <lists at cheimes.de> wrote:
>
>
> > Indeed! It's one character shorter than "pass", it requires much less
> > finger movement and it even looks cool. I like it
> >
> > However ... can lead to strange looking code, too:
> >
> > >>> ....__class__.__name__
> > 'ellipsis'
>
> So ellipsis is a class?
>
> Can it be subclassed as in:
>
> class myclass(...):
>    pass


No, Ellipsis is a singleton, like None. ellipsis is Ellipsis's type, and you
can't subclass it:

>>> ...
Ellipsis

>>> Ellipsis
Ellipsis

>>> type(...)
<type 'ellipsis'>

>>> class Spam(...): pass
...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: cannot create 'ellipsis' instances

>>> class Spam(type(...)): pass
...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: type 'ellipsis' is not an acceptable base type

 Compare with None:

>>> type(None)
<type 'NoneType'>

>>> class Spam(None): pass
...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: cannot create 'NoneType' instances

>>> class Spam(type(None)): pass
...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: type 'NoneType' is not an acceptable base type

-- 
Thomas Wouters <thomas at python.org>

Hi! I'm a .signature virus! copy me into your .signature file to help me
spread!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-3000/attachments/20080124/285518a0/attachment.htm 


More information about the Python-3000 mailing list