[Python-Dev] ctypes: is it intentional that id() is the only way to get the address of an object?

Greg Ewing greg.ewing at canterbury.ac.nz
Fri Jan 18 19:28:06 EST 2019


Tim Peters wrote:

> The dict itself keeps the objects alive.

Yes, but the idea of a cache is that you're free to flush
things out of it to make room for something else without
breaking anything.

It sounds like MRAB is using ids as weak references,
without the assurance actual weak references give you
that they become invalidated when the refefenced object
goes away,

> No such uses care about object addresses, though - just that id(obj)
> returns a value usable as a dict key, unique among all reachable
> objects at the time `id()` is called.

Yep. In hindsight it was probably a mistake for the docs
to talk about addresses in relation to id() -- it seems to
have given some people unrealistic expectations.

-- 
Greg


More information about the Python-Dev mailing list