A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2015-September/141612.html below:

[Python-Dev] semantics of subclassing things from itertools

[Python-Dev] semantics of subclassing things from itertoolsMaciej Fijalkowski fijall at gmail.com
Sun Sep 13 09:49:23 CEST 2015
On Fri, Sep 11, 2015 at 1:48 AM, Raymond Hettinger
<raymond.hettinger at gmail.com> wrote:
>
>> On Sep 10, 2015, at 3:23 AM, Maciej Fijalkowski <fijall at gmail.com> wrote:
>>
>> I would like to know what are the semantics if you subclass something
>> from itertools (e.g. islice).
>>
>> Right now it's allowed and people do it, which is why the
>> documentation is incorrect. It states "equivalent to: a function-or a
>> generator", but you can't subclass whatever it is equivalent to, which
>> is why in PyPy we're unable to make it work in pure python.
>>
>> I would like some clarification on that.
>
> The docs should say "roughly equivalent to" not "exactly equivalent to".
> The intended purpose of the examples in the itertools docs is to use
> pure python code to help people better understand each tool.  It is not
> is intended to dictate that tool x is a generator or is a function.
>
> The intended semantics are that the itertools are classes (not functions
> and not generators).  They are intended to be sub-classable (that is
> why they have Py_TPFLAGS_BASETYPE defined).

Ok, so what's completely missing from the documentation is what *are*
the semantics of subclasses of those classes? Can you override any
magic methods? Can you override next (which is or isn't a magic method
depending how you look)? Etc.

The documentation on this is completely missing and it's left guessing
with "whatever cpython happens to be doing".
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4