The Python collections.abc
module contains many handy ABCs for checking various features of objects, but one that doesn't appear to belong is Callable
. No standard collection is callable, and PEP 3119
doesn't provide any reasoning or even mention the Callable ABC, so why is it in this package instead of somewhere else?
Context: I'm writing a Python->Java compiler for fun, and I just wanted to see if there was any reasoning behind the decision so I could list that reasoning in my code.
Source code: Lib/_collections_abc.py. This module provides abstract base classes that can be used to test whether a class provides a particular interface; for example, whether it is hashable or whether it is a mapping. An issubclass() or isinstance() test for an interface works in one of three ways.
The 'abc' module in the Python library provides the infrastructure for defining custom abstract base classes. Abstract class cannot be instantiated in python. An Abstract method can be call by its subclasses.
Python has a module called abc (abstract base class) that offers the necessary tools for crafting an abstract base class. First and foremost, you should understand the ABCMeta metaclass provided by the abstract base class. The rule is every abstract class must use ABCMeta metaclass.
To conclude this Python Sequence and collection tutorial, we will say that a sequence has a deterministic ordering, but a collection does not. Examples of sequences include strings, lists, tuples, bytes sequences, bytes arrays, and range objects. Those of collections include sets and dictionaries.
The module originates from PEP-3119 which proposes:
Specific ABCs for containers and iterators, to be added to the collections module.
But since then, it evolved to be something more. And now a module description does not mention containters and iterators explictly. It says:
This module provides abstract base classes that can be used to test whether a class provides a particular interface; for example, whether it is hashable or whether it is a mapping.
I believe it is a collections
submodule just because it was a part of it in the past:
New in version 3.3: Formerly, this module was part of the collections module.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With