summaryrefslogtreecommitdiffstats
path: root/Lib/_collections_abc.py
diff options
context:
space:
mode:
authorRaymond Hettinger <rhettinger@users.noreply.github.com>2022-05-12 18:18:39 (GMT)
committerGitHub <noreply@github.com>2022-05-12 18:18:39 (GMT)
commita834e2d8e1230c17193c19b425e83e0bf736179e (patch)
treeee41b99b0d16ae1bc642f98cabcf62990d75eb93 /Lib/_collections_abc.py
parent079f0dd7191fbadd4c3a5899b6af12492e84d2b4 (diff)
downloadcpython-a834e2d8e1230c17193c19b425e83e0bf736179e.zip
cpython-a834e2d8e1230c17193c19b425e83e0bf736179e.tar.gz
cpython-a834e2d8e1230c17193c19b425e83e0bf736179e.tar.bz2
Add notes for maintaining ABCs (#92736)
Diffstat (limited to 'Lib/_collections_abc.py')
-rw-r--r--Lib/_collections_abc.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/Lib/_collections_abc.py b/Lib/_collections_abc.py
index e96e4c3..c62233b 100644
--- a/Lib/_collections_abc.py
+++ b/Lib/_collections_abc.py
@@ -6,6 +6,32 @@
Unit tests are in test_collections.
"""
+############ Maintenance notes #########################################
+#
+# ABCs are different from other standard library modules in that they
+# specify compliance tests. In general, once an ABC has been published,
+# new methods (either abstract or concrete) cannot be added.
+#
+# Though classes that inherit from an ABC would automatically receive a
+# new mixin method, registered classes would become non-compliant and
+# violate the contract promised by ``isinstance(someobj, SomeABC)``.
+#
+# Though irritating, the correct procedure for adding new abstract or
+# mixin methods is to create a new ABC as a subclass of the previous
+# ABC. For example, union(), intersection(), and difference() cannot
+# be added to Set but could go into a new ABC that extends Set.
+#
+# Because they are so hard to change, new ABCs should have their APIs
+# carefully thought through prior to publication.
+#
+# Since ABCMeta only checks for the presence of methods, it is possible
+# to alter the signature of a method by adding optional arguments
+# or changing parameters names. This is still a bit dubious but at
+# least it won't cause isinstance() to return an incorrect result.
+#
+#
+#######################################################################
+
from abc import ABCMeta, abstractmethod
import sys