[Python-Dev] Update on PEP 523 and adding a co_extra field to code objects (original) (raw)

Antoine Pitrou solipsis at pitrou.net
Tue Aug 30 13:48:13 EDT 2016


On Tue, 30 Aug 2016 17:35:35 +0000 Brett Cannon <brett at python.org> wrote:

> > Perhaps a list would work indeed. Realistically, if there are at most > 2-3 users of the field at any given time (and most probably only one or > zero), a simple type check (by pointer equality) on each list item may > be sufficient. >

Let's see what Maciej says, but we could standardize on switching the field to a list when a conflict of usage is detected so the common case in the frame eval function is checking for your own type, and if that fails then doing a PyListCheckExact() and look for your object, otherwise make a list and move over to that for everyone to use. A little bit more code, but it's simple code and takes care of conflicts only when it calls for it.

That's a bit obscure and confusing, though (I think the weakref module uses a similar kludge in some place). If you want to iterate on it you have to write some bizarre macro to share the loop body between the two different code-paths (list / non-list), or some equally tedious function-pointer-based code.

Why not make it always a list? List objects are reasonably cheap in memory and access time... (unlike dicts)

Regards

Antoine.



More information about the Python-Dev mailing list