classification
Title: Clarify that atexit.unregister matches by equality, not identity
Type: Stage: resolved
Components: Documentation Versions: Python 3.11, Python 3.10, Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, iritkatriel, jack__d, mark.dickinson, miss-islington
Priority: normal Keywords: easy, patch

Created on 2019-09-09 08:51 by mark.dickinson, last changed 2021-06-29 18:22 by iritkatriel. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 26935 merged jack__d, 2021-06-28 15:21
PR 26956 merged miss-islington, 2021-06-29 17:28
PR 26957 merged miss-islington, 2021-06-29 17:28
Messages (4)
msg351363 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2019-09-09 08:51
Suppose I have a class that looks like this:

    class A:
        def cleanup(self):
            print("Doing essential cleanup")

and on an instance `a = A()`, I do: `atexit.register(a.cleanup)`.

Then it's not obvious from the documentation that an `atexit.unregister(a.cleanup)` will successfully undo the effect of the reigster call: the second `a.cleanup` is a different object from the first:

    >>> a = A()
    >>> clean1 = a.cleanup
    >>> clean2 = a.cleanup
    >>> clean1 is clean2
    False

Luckily, though the two bound methods are different objects, they're equal:

    >>> clean1 == clean2
    True

and from looking at the source, it's apparent that `atexit.unregister` compares by equality rather than identity, so everything works.

It would be good to add a sentence to the documentation for `atexit.unregister` to clarify that this can be expected to work.
msg396748 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-06-29 17:28
New changeset 12803c59d54ff1a45a5b08cef82652ef199b3b07 by Jack DeVries in branch 'main':
bpo-38062: [doc] clarify that atexit uses equality comparisons internally. (GH-26935)
https://github.com/python/cpython/commit/12803c59d54ff1a45a5b08cef82652ef199b3b07
msg396751 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-06-29 17:52
New changeset 08aa26e4355da6f916da0c97d00774800ee0fc46 by Miss Islington (bot) in branch '3.10':
bpo-38062: [doc] clarify that atexit uses equality comparisons internally. (GH-26935) (GH-26956)
https://github.com/python/cpython/commit/08aa26e4355da6f916da0c97d00774800ee0fc46
msg396752 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-06-29 17:53
New changeset 02859df10591789c72eb185a4f7dd9cc1ea8dcbb by Miss Islington (bot) in branch '3.9':
bpo-38062: [doc] clarify that atexit uses equality comparisons internally. (GH-26935) (GH-26957)
https://github.com/python/cpython/commit/02859df10591789c72eb185a4f7dd9cc1ea8dcbb
History
Date User Action Args
2021-06-29 18:22:49iritkatrielsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2021-06-29 17:53:10iritkatrielsetmessages: + msg396752
2021-06-29 17:52:56iritkatrielsetmessages: + msg396751
2021-06-29 17:28:23miss-islingtonsetpull_requests: + pull_request25523
2021-06-29 17:28:17miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request25522
2021-06-29 17:28:12iritkatrielsetnosy: + iritkatriel
messages: + msg396748
2021-06-28 15:21:04jack__dsetkeywords: + patch
nosy: + jack__d

pull_requests: + pull_request25504
stage: patch review
2021-06-27 19:12:34iritkatrielsetkeywords: + easy
versions: + Python 3.9, Python 3.10, Python 3.11, - Python 3.7, Python 3.8
2019-09-09 08:52:05mark.dickinsonsetassignee: docs@python

nosy: + docs@python
components: + Documentation
versions: + Python 3.7, Python 3.8
2019-09-09 08:51:28mark.dickinsoncreate