all Python 3weakrefterm
weakref.ProxyType
weak references
The type of proxy that weakref.proxy() returns for a non-callable object. It is for isinstance checks; you cannot create it directly.
Syntax
type(p) is weakref.ProxyType
A proxy imitates almost all of the object's behaviour but not its type: type(p) is ProxyType, not the object's class, and isinstance(p, User) is True only because the proxy forwards __class__. To tell that you hold a proxy, compare type(p) against the weakref.ProxyTypes tuple — it covers CallableProxyType too.
Examples
import weakref
class User:
pass
u = User()
p = weakref.proxy(u)
print(type(p) is weakref.ProxyType, type(p) is User) # → True False
print(isinstance(p, User), type(p) in weakref.ProxyTypes) # → True True
See also
Open in the full glossarydocs.python.orgReport an inaccuracy