[Python-ideas] Where to put non-collection ABCs (was: Deprecating the old-style sequence protocol)

M.-A. Lemburg mal at egenix.com
Mon Dec 28 12:58:54 EST 2015


On 28.12.2015 18:42, Brett Cannon wrote:
> Speaking of using ABCs more, where should we put ABCs which have nothing to
> do with collections? As of right now all ABCs seem to get shoved into
> collections.abc, but e.g. Awaitable and Coroutine are not types of
> collections. I personally want to add a context manager ABC with a default
> __exit__.
> 
> I opened http://bugs.python.org/issue25637 to discuss this, but I figured a
> wider discussion wouldn't hurt. Some suggest just putting the ABCs into the
> abc module. We could create an interfaces module (top-level or a submodule
> of ABC). The other option is to put the ABCs in subject-specific modules,
> so my context manager one would go into contextlib (either top-level or an
> abc submodule); don't know where the coroutine ones would go since it might
> be overloading asyncio if we out them there.
> 
> Anyway, the key point is collections.abc is starting to get non-collections
> stuff and if we are going to start pushing ABCs more we should decide how
> we want to organize them in general in the stdlib and instead of dumping
> them into collections.abc.

I'd put them into the abc module (perhaps turning this into a
package, if things get too crowded).

collections.abc could then do a "from abc import *" for b/w
compatibility.

> On Sun, Dec 27, 2015, 09:35 Guido van Rossum <guido at python.org> wrote:
> 
>> I think there's a lot of interesting stuff in this thread. Personally I
>> don't think we should strive to distinguish between mappings and sequences
>> structurally. We should instead continue to encourage inheriting from (or
>> registering with) the corresponding ABCs. The goal is to ensure that
>> there's one best-practice way to distinguish mappings from sequences, and
>> it's by using isinstance(x, Sequence) or isinstance(x, Mapping).
>>
>> If we want some way to turn something that just defines __getitem__ and
>> __len__ into a proper sequence, it should just be made to inherit from
>> Sequence, which supplies the default __iter__ and __reversed__.
>> (Registration is *not* good enough here.) If we really want a way to turn
>> something that just supports __getitem__ into an Iterable maybe we can
>> provide an additional ABC for that purpose; let's call it a HalfSequence
>> until we've come up with a better name. (We can't use Iterable for this
>> because Iterable should not reference __getitem__.)
>>
>> I also think it's fine to introduce Reversible as another ABC and
>> carefully fit it into the existing hierarchy. It should be a one-trick pony
>> and be another base class for Sequence; it should not have a default
>> implementation. (But this has been beaten to death in other threads -- it's
>> time to just file an issue with a patch.)
>>
>>
>> --
>> --Guido van Rossum (python.org/~guido)
>>
> _______________________________________________
>> Python-ideas mailing list
>> Python-ideas at python.org
>> https://mail.python.org/mailman/listinfo/python-ideas
>> Code of Conduct: http://python.org/psf/codeofconduct/
> 

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Experts (#1, Dec 28 2015)
>>> Python Projects, Coaching and Consulting ...  http://www.egenix.com/
>>> Python Database Interfaces ...           http://products.egenix.com/
>>> Plone/Zope Database Interfaces ...           http://zope.egenix.com/
________________________________________________________________________

::: We implement business ideas - efficiently in both time and costs :::

   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611
               http://www.egenix.com/company/contact/
                      http://www.malemburg.com/



More information about the Python-ideas mailing list