summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBénédikt Tran <10796600+picnixz@users.noreply.github.com>2024-08-07 13:40:19 (GMT)
committerGitHub <noreply@github.com>2024-08-07 13:40:19 (GMT)
commit76bdeebef6c6206f3e0af1e42cbfc75c51fbb8ca (patch)
tree3f60ac0e8ea26622bce53211290d1a88248dedb1
parent674a50ef2f8909c1c5d812e166bcc12ae6377908 (diff)
downloadcpython-76bdeebef6c6206f3e0af1e42cbfc75c51fbb8ca.zip
cpython-76bdeebef6c6206f3e0af1e42cbfc75c51fbb8ca.tar.gz
cpython-76bdeebef6c6206f3e0af1e42cbfc75c51fbb8ca.tar.bz2
gh-122511: Improve documentation for object identity of mutable/immutable types (#122512)
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
-rw-r--r--Doc/reference/datamodel.rst16
1 files changed, 10 insertions, 6 deletions
diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst
index aa61fbd..f099d55 100644
--- a/Doc/reference/datamodel.rst
+++ b/Doc/reference/datamodel.rst
@@ -106,12 +106,16 @@ that mutable object is changed.
Types affect almost all aspects of object behavior. Even the importance of
object identity is affected in some sense: for immutable types, operations that
compute new values may actually return a reference to any existing object with
-the same type and value, while for mutable objects this is not allowed. E.g.,
-after ``a = 1; b = 1``, ``a`` and ``b`` may or may not refer to the same object
-with the value one, depending on the implementation, but after ``c = []; d =
-[]``, ``c`` and ``d`` are guaranteed to refer to two different, unique, newly
-created empty lists. (Note that ``c = d = []`` assigns the same object to both
-``c`` and ``d``.)
+the same type and value, while for mutable objects this is not allowed.
+For example, after ``a = 1; b = 1``, *a* and *b* may or may not refer to
+the same object with the value one, depending on the implementation.
+This is because :class:`int` is an immutable type, so the reference to ``1``
+can be reused. This behaviour depends on the implementation used, so should
+not be relied upon, but is something to be aware of when making use of object
+identity tests.
+However, after ``c = []; d = []``, *c* and *d* are guaranteed to refer to two
+different, unique, newly created empty lists. (Note that ``e = f = []`` assigns
+the *same* object to both *e* and *f*.)
.. _types: