[Python-ideas] threading lock and isinstance

Jacco van Dorp j.van.dorp at deonet.nl
Thu Mar 29 05:43:20 EDT 2018


Currently, you cannot use isinstance checks on threading locks, because
they're created by a factory function instead of being actual classes.

Now that we've got __subclasshook__  and __instancecheck__, is there
still a reason other than "history" that we can't use isinstance here ? There
could exist a thin wrapper class along the lines of:

class Lock:
    def __new__():
        return __allocate_lock()  # Call factory function

    @classmethod
    def __subclasshook__(cls, inst):
        # code...

As far as I can think, no code would be broken by this - even current
introspection
which we're trying to replace would work just fine.

My C experience is rather limited, so i dont know if it's hard to
write the subclass
/isinstance checks.

While probably not that important, would people consider this to be a
good idea ?

(I found this bug report: https://bugs.python.org/issue3352 which has
a post of Nick Coghlan  from 2008-07-14 22:25 where this is mentioned
- but in respect to multiprocessing. However, that thread is rather
old and dead. I could not find any other references to this.)


More information about the Python-ideas mailing list