Skip to content

Commit a834e2d

Browse files
authored
Add notes for maintaining ABCs (#92736)
1 parent 079f0dd commit a834e2d

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

Lib/_collections_abc.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,32 @@
66
Unit tests are in test_collections.
77
"""
88

9+
############ Maintenance notes #########################################
10+
#
11+
# ABCs are different from other standard library modules in that they
12+
# specify compliance tests. In general, once an ABC has been published,
13+
# new methods (either abstract or concrete) cannot be added.
14+
#
15+
# Though classes that inherit from an ABC would automatically receive a
16+
# new mixin method, registered classes would become non-compliant and
17+
# violate the contract promised by ``isinstance(someobj, SomeABC)``.
18+
#
19+
# Though irritating, the correct procedure for adding new abstract or
20+
# mixin methods is to create a new ABC as a subclass of the previous
21+
# ABC. For example, union(), intersection(), and difference() cannot
22+
# be added to Set but could go into a new ABC that extends Set.
23+
#
24+
# Because they are so hard to change, new ABCs should have their APIs
25+
# carefully thought through prior to publication.
26+
#
27+
# Since ABCMeta only checks for the presence of methods, it is possible
28+
# to alter the signature of a method by adding optional arguments
29+
# or changing parameters names. This is still a bit dubious but at
30+
# least it won't cause isinstance() to return an incorrect result.
31+
#
32+
#
33+
#######################################################################
34+
935
from abc import ABCMeta, abstractmethod
1036
import sys
1137

Lib/numbers.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,31 @@
55
66
TODO: Fill out more detailed documentation on the operators."""
77

8+
############ Maintenance notes #########################################
9+
#
10+
# ABCs are different from other standard library modules in that they
11+
# specify compliance tests. In general, once an ABC has been published,
12+
# new methods (either abstract or concrete) cannot be added.
13+
#
14+
# Though classes that inherit from an ABC would automatically receive a
15+
# new mixin method, registered classes would become non-compliant and
16+
# violate the contract promised by ``isinstance(someobj, SomeABC)``.
17+
#
18+
# Though irritating, the correct procedure for adding new abstract or
19+
# mixin methods is to create a new ABC as a subclass of the previous
20+
# ABC.
21+
#
22+
# Because they are so hard to change, new ABCs should have their APIs
23+
# carefully thought through prior to publication.
24+
#
25+
# Since ABCMeta only checks for the presence of methods, it is possible
26+
# to alter the signature of a method by adding optional arguments
27+
# or changing parameter names. This is still a bit dubious but at
28+
# least it won't cause isinstance() to return an incorrect result.
29+
#
30+
#
31+
#######################################################################
32+
833
from abc import ABCMeta, abstractmethod
934

1035
__all__ = ["Number", "Complex", "Real", "Rational", "Integral"]

0 commit comments

Comments
 (0)