From d39b296620c6c7dd414edf7de084b99eef9b56a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Wed, 31 Jul 2024 10:59:33 +0200 Subject: [PATCH 1/4] improve documentation --- Doc/reference/datamodel.rst | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index 144c6f78ccd443..ced9f44d283fd4 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -103,15 +103,18 @@ of the immediately contained objects are implied. So, if an immutable container (like a tuple) contains a reference to a mutable object, its value changes if 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``.) +Types affect almost all aspects of object behavior. Even the importance of +object identity is affected in some sense. + +For immutable types such as :class:`int` or :class:`str`, operations that +compute new values may actually return a reference to any existing object +with the same type and value, e.g., after ``a = 1; b = 1``, *a* and *b* may +or may not refer to the same object with the value one. + +For mutable types such as :class:`list` or :class:`dict`, this is not allowed, +e.g., 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: From 0ee195ba407a725f7b894780be1767081c35628a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Sun, 4 Aug 2024 12:38:32 +0200 Subject: [PATCH 2/4] Update Doc/reference/datamodel.rst Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> --- Doc/reference/datamodel.rst | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index ced9f44d283fd4..dc08d6505d2be6 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -103,17 +103,18 @@ of the immediately contained objects are implied. So, if an immutable container (like a tuple) contains a reference to a mutable object, its value changes if 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 such as :class:`int` or :class:`str`, operations that -compute new values may actually return a reference to any existing object -with the same type and value, e.g., after ``a = 1; b = 1``, *a* and *b* may -or may not refer to the same object with the value one. - -For mutable types such as :class:`list` or :class:`dict`, this is not allowed, -e.g., after ``c = []; d = []``, *c* and *d* are guaranteed to refer to two -different, unique, newly created empty lists (note that ``e = f = []`` assigns +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. +For example, after ``a = 1; b = 1``, ``a`` and ``b`` may or may not refer to +the same objectw ith 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 is dependant 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*). From e826c182b8bd5cc7c9bff4e335fe2fd466b84b7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Sun, 4 Aug 2024 12:42:27 +0200 Subject: [PATCH 3/4] fixup! lint --- Doc/reference/datamodel.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index dc08d6505d2be6..a8bf0829369fd1 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -107,15 +107,15 @@ 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. -For example, after ``a = 1; b = 1``, ``a`` and ``b`` may or may not refer to -the same objectw ith the value one, depending on the implementation. +For example, after ``a = 1; b = 1``, *a* and *b* may or may not refer to +the same object ith 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 is dependant on the implementation used, -so should not be relied upon, but is something to be aware of when making use of -object identity tests. +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*). +the *same* object to both *e* and *f*.) .. _types: From 80edf11418a6ed229f41cb1269c227af8e06944c Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Date: Wed, 7 Aug 2024 14:20:48 +0100 Subject: [PATCH 4/4] spelling --- Doc/reference/datamodel.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index a8bf0829369fd1..ecf0f86529c9a1 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -108,7 +108,7 @@ 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. For example, after ``a = 1; b = 1``, *a* and *b* may or may not refer to -the same object ith the value one, depending on the implementation. +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