This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients mark.dickinson, pitrou, rhettinger, serhiy.storchaka, tim.peters, vstinner
Date 2020-04-22.14:26:16
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1587565576.53.0.0654157072071.issue40346@roundup.psfhosted.org>
In-reply-to
Content
In Python 3.8, random.Random docstring starts with "Random number generator base class".

I do understand that the random module design predates the abc module (added to Python 2.7). I'm now proposing to add a real base class to move it towards modern Python stdlib coding style.


That's the behavior that I would expect from a "base class":

>>> class MySequence(collections.abc.Sequence): pass
... 
>>> seq=MySequence()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Can't instantiate abstract class MySequence with abstract methods __getitem__, __len__

Some examples of stdlib modules which implement base classes like this:

* collections.abc.Sequence
* numbers.Complex
* selectors.BaseSelector
* typing.SupportsInt

asyncio.AbstractEventLoop doesn't fail when an instance is created, but when an abstract method is created. Users can choose to inherit from asyncio.BaseEventLoop or asyncio.AbstractEventLoop depending if they wany to inherit partially of BaseEventLoop features, or really create an event loop from scratch (AbstractEventLoop). Other classes which are designed like that:

* email._policybase.Policy
* http.cookiejar.CookiePolicy
* importlib.abc.Loader
* wsgiref.handlers.BaseHandler

I don't think that it's worth it to bother with abc.ABC abstraction here, and so I only propose to provide methods which are implemented as "raise NotImplementedError".
History
Date User Action Args
2020-04-22 14:26:16vstinnersetrecipients: + vstinner, tim.peters, rhettinger, mark.dickinson, pitrou, serhiy.storchaka
2020-04-22 14:26:16vstinnersetmessageid: <1587565576.53.0.0654157072071.issue40346@roundup.psfhosted.org>
2020-04-22 14:26:16vstinnerlinkissue40346 messages
2020-04-22 14:26:16vstinnercreate