Skip to content
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

Clarify that atexit.unregister matches by equality, not identity #82243

Closed
mdickinson opened this issue Sep 9, 2019 · 4 comments
Closed

Clarify that atexit.unregister matches by equality, not identity #82243

mdickinson opened this issue Sep 9, 2019 · 4 comments
Labels
3.9 only security fixes 3.10 only security fixes 3.11 only security fixes docs Documentation in the Doc dir easy

Comments

@mdickinson
Copy link
Member

BPO 38062
Nosy @mdickinson, @miss-islington, @iritkatriel, @jdevries3133
PRs
  • bpo-38062: [doc] clarify that atexit uses equality comparisons internally. #26935
  • [3.10] bpo-38062: [doc] clarify that atexit uses equality comparisons internally. (GH-26935) #26956
  • [3.9] bpo-38062: [doc] clarify that atexit uses equality comparisons internally. (GH-26935) #26957
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2021-06-29.18:22:49.469>
    created_at = <Date 2019-09-09.08:51:28.823>
    labels = ['easy', '3.11', '3.9', '3.10', 'docs']
    title = 'Clarify that atexit.unregister matches by equality, not identity'
    updated_at = <Date 2021-06-29.18:22:49.468>
    user = 'https://github.com/mdickinson'

    bugs.python.org fields:

    activity = <Date 2021-06-29.18:22:49.468>
    actor = 'iritkatriel'
    assignee = 'docs@python'
    closed = True
    closed_date = <Date 2021-06-29.18:22:49.469>
    closer = 'iritkatriel'
    components = ['Documentation']
    creation = <Date 2019-09-09.08:51:28.823>
    creator = 'mark.dickinson'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 38062
    keywords = ['patch', 'easy']
    message_count = 4.0
    messages = ['351363', '396748', '396751', '396752']
    nosy_count = 5.0
    nosy_names = ['mark.dickinson', 'docs@python', 'miss-islington', 'iritkatriel', 'jack__d']
    pr_nums = ['26935', '26956', '26957']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue38062'
    versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']

    @mdickinson
    Copy link
    Member Author

    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.

    @mdickinson mdickinson added docs Documentation in the Doc dir 3.7 (EOL) end of life 3.8 only security fixes labels Sep 9, 2019
    @iritkatriel iritkatriel added easy 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes and removed 3.7 (EOL) end of life 3.8 only security fixes labels Jun 27, 2021
    @iritkatriel
    Copy link
    Member

    New changeset 12803c5 by Jack DeVries in branch 'main':
    bpo-38062: [doc] clarify that atexit uses equality comparisons internally. (GH-26935)
    12803c5

    @iritkatriel
    Copy link
    Member

    New changeset 08aa26e by Miss Islington (bot) in branch '3.10':
    bpo-38062: [doc] clarify that atexit uses equality comparisons internally. (GH-26935) (GH-26956)
    08aa26e

    @iritkatriel
    Copy link
    Member

    New changeset 02859df by Miss Islington (bot) in branch '3.9':
    bpo-38062: [doc] clarify that atexit uses equality comparisons internally. (GH-26935) (GH-26957)
    02859df

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 only security fixes 3.10 only security fixes 3.11 only security fixes docs Documentation in the Doc dir easy
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants