Changes between Initial Version and Version 1 of Ticket #14711, comment 122

Oct 7, 2013, 5:58:06 PM (9 years ago)
Nils Bruin


  • Ticket #14711, comment 122

    initial v1  
    1616Ah. I didn't realize that. You say that `_coerce_from_hash` is not considered by backtracking. Indeed, that changes things. In that case, `_coerce_from_list` could be a "weak set" (e.g., a `WeakValueDictionary` with trivial keys), since the maps are kept alive by their entries in `_coerce_from_hash`, where the key is kept alive by the `_registered_domains`. This would get rid of the garbage collection problem, if we ever want to have maps that help coercion discovery but don't have lifetime implications.
    18 >
    19 > > The same applies to `_register_embedding`, although perhaps the coercion discovery treats the store differently, and storing a strong reference to even a weakened map implies a strong reference to the codomain.
    20 >
    21 > All weakened maps still have a ''strong'' reference to the codomain. Only the reference to the domain will be weak. And `register_embedding` is still simply assigning the embedding to an attribute `_embedding` of the domain.
    22 >
    23 > > Other question, does `_parent=None` imply a weakened map? (I guess isinstance(_domain,weakref.ref) definintely does) or are there other reasons for the parent to be unset?
    24 >
    25 > I guess one could test `self._parent is None`, rather than typetest stuff. This should actually be faster.
    26 >
    27 > Concerning "reasons": The parent is unset, because otherwise we have a chain of references from the map to the domain, namely via the parent (i.e., the homset). Hence, having a weak reference from the map to the domain would be futile if there is a reference from the map to its parent. Note that alternatively one could have a weak reference from the ''homset'' to the domain. But I think we have agreed above that we don't want this as a default.