[Python-Dev] PEP 205 comments
Martin v. Loewis
Fri, 12 Jan 2001 23:19:57 +0100
Before commenting on the patch itself, I'd like to comment on the
patch describing it.
I'm missing a discussion as to why weak references don't act as
proxies (or why they do now). A weak proxy would provide the same
attributes as the object which it encapsulates, so it could be used
transparently in place of the original object. I can think of a number
of reasons why it is not done this way (e.g. complete transparency is
impossible to achieve); now that a revision of the patch provides
proxies, the documentation should state which features are forwarded
to the proxy and which aren't (it lists the type() as a difference,
but I doubt that is the only difference - repr is also different).
Next, I wonder whether weakref.new is allowed to return an existing
weak reference to the same object. If that is not acceptable, I'd like
to know why - if it was acceptable, then weakref.new(instance)
(i.e. without callback) could return the same weak reference all the
time. A smart implementation might chose to put the weak reference
with no callback in the start of the list, so creation of additional
weak references to the same object would be inexpensive.
Likewise, I'd like to know the rationale for the clear method. Why is
it desirable to drop the object, yet keep the weak reference? Isn't it
easier for the application to either ignore clearing altogether, or
dropping the reference to the weak reference? So I'd propose to kill
the clear method.
Again on proxies, there is no discussion or documentation of the
ReferenceError. Why is it a RuntimeError? LookupError, ValueError, and
AttributeError seem to be just as fine or better.
On to the type type extensions: Should there be a type flag indicating
presence of tp_weaklistoffset? It appears that the type structure had
tp_xxx7 for a long time, so likely all in-use binary modules have
that field set to zero. Is that sufficient?
Thanks for reading all of this message,