Some minor updates to reflect the removal of .clear(). Added information
(preliminary) about proxy objects.
This commit is contained in:
parent
bd39cf0ae3
commit
1f0aa4313d
38
pep-0205.txt
38
pep-0205.txt
|
@ -74,11 +74,13 @@ Proposed Solution
|
|||
references to external resources (database connections, open
|
||||
files, etc.).
|
||||
|
||||
A new module, weakref, will contain two new functions used to
|
||||
create weak references. weakref.new() will create a "weak
|
||||
reference object" and optionally attach a callback which will be
|
||||
called when the object is about to be finalized.
|
||||
weakref.mapping() will create a "weak dictionary".
|
||||
A new module, weakref, will contain new functions used to create
|
||||
weak references. weakref.new() will create a "weak reference
|
||||
object" and optionally attach a callback which will be called when
|
||||
the object is about to be finalized. weakref.mapping() will
|
||||
create a "weak dictionary". A third function, weakref.proxy(),
|
||||
will create a proxy object that behaves somewhat like the original
|
||||
object.
|
||||
|
||||
A weak reference object will allow access to the referenced object
|
||||
if it hasn't been collected and to determine if the object still
|
||||
|
@ -99,13 +101,25 @@ Proposed Solution
|
|||
to be finalized), and will be unregistered from the object. Like
|
||||
dictionaries, weak dictionaries are not hashable.
|
||||
|
||||
The callbacks registered with weak reference objects or in weak
|
||||
dictionaries must accept a single parameter, which will be the
|
||||
weak-ly referenced object itself. The object can be resurrected
|
||||
by creating some other reference to the object in the callback, in
|
||||
which case the weak reference generating the callback will still
|
||||
be cleared but no weak references remaining to the object will be
|
||||
cleared.
|
||||
Proxy objects are weak references that attempt to behave like the
|
||||
object they proxy, as much as they can. Regardless of the
|
||||
underlying type, proxies are not hashable since their ability to
|
||||
act as a weak reference relies on a fundamental mutability that
|
||||
will cause failures when used as dictionary keys -- even if the
|
||||
proper hash value is computed before the referent dies, the
|
||||
resulting proxy cannot be used as a dictionary key since it cannot
|
||||
be compared once the referent has expired, and comparability is
|
||||
necessary for dictionary keys. Operations on proxy objects after
|
||||
the referent dies cause weakref.ReferenceError to be raised in
|
||||
most cases. "is" comparisons, type(), and id() will continue to
|
||||
work, but always refer to the proxy and not the referent.
|
||||
|
||||
The callbacks registered with weak references must accept a single
|
||||
parameter, which will be the weak-ly referenced object itself.
|
||||
The object can be resurrected by creating some other reference to
|
||||
the object in the callback, in which case the weak reference
|
||||
generating the callback will still be cleared but no remaining
|
||||
weak references to the object will be cleared.
|
||||
|
||||
|
||||
Implementation Strategy
|
||||
|
|
Loading…
Reference in New Issue