New submission from Mark Dickinson <dicki...@gmail.com>:

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.

----------
messages: 351363
nosy: mark.dickinson
priority: normal
severity: normal
status: open
title: Clarify that atexit.unregister matches by equality, not identity

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue38062>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to