Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Improve the documentation for identity semantics of mutable and immutable types #122511

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
picnixz opened this issue Jul 31, 2024 · 1 comment
Closed
Labels
docs Documentation in the Doc dir

Comments

@picnixz
Copy link
Member

picnixz commented Jul 31, 2024

Current paragraph:

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.)

Proposed changes:

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).

cc @mdeiana @terryjreedy

Related: #122463

Linked PRs

@picnixz picnixz added the docs Documentation in the Doc dir label Jul 31, 2024
AA-Turner added a commit that referenced this issue Aug 7, 2024
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Aug 7, 2024
…/immutable types (pythonGH-122512)

(cherry picked from commit 76bdeeb)

Co-authored-by: Bénédikt Tran <[email protected]>
Co-authored-by: Adam Turner <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Aug 7, 2024
…/immutable types (pythonGH-122512)

(cherry picked from commit 76bdeeb)

Co-authored-by: Bénédikt Tran <[email protected]>
Co-authored-by: Adam Turner <[email protected]>
AA-Turner added a commit that referenced this issue Aug 7, 2024
…e/immutable types (GH-122512) (#122779)

gh-122511: Improve documentation for object identity of mutable/immutable types (GH-122512)
(cherry picked from commit 76bdeeb)

Co-authored-by: Bénédikt Tran <[email protected]>
Co-authored-by: Adam Turner <[email protected]>
AA-Turner added a commit that referenced this issue Aug 7, 2024
…e/immutable types (GH-122512) (#122778)

gh-122511: Improve documentation for object identity of mutable/immutable types (GH-122512)
(cherry picked from commit 76bdeeb)

Co-authored-by: Bénédikt Tran <[email protected]>
Co-authored-by: Adam Turner <[email protected]>
@picnixz
Copy link
Member Author

picnixz commented Aug 7, 2024

Completed in the corresponding PRs.

@picnixz picnixz closed this as completed Aug 7, 2024
blhsing pushed a commit to blhsing/cpython that referenced this issue Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir
Projects
None yet
Development

No branches or pull requests

1 participant