[Python-Dev] Identifier API

"Martin v. Löwis" martin at v.loewis.de
Thu Oct 13 14:00:38 CEST 2011


> I like this better too because of the all-caps macro name.  Something about
> seeing "Py_identifier" look like a function call and having it add the magical
> PyId_update local bugs me.  It just looks wrong, whereas the all-caps is more
> of a cultural clue that something else is going on.

If people think the macro should be all upper-case, I can go through and 
replace them (but only once). Let me know what the exact spelling
should be.

Originally, I meant to make the variable name equal the string (e.g.
then having a variable named __init__ point to the "__init__" string).
However, I quickly gave up on that idea, since the strings conflict
too often with other identifiers in C. In particular, you couldn't
use that approach for calling the "fileno", "read" or "write" methods.

So I think it needs a prefix. If you don't like PyId_, let me know
what the prefix should be instead.

If there is no fixed prefix (i.e. if you have to specify variable
name and string value separately), and if there is no error checking,
there is IMO too little gain to make this usable. I'm particularly
worried about the error checking: the tricky part in C is to keep
track of all the code paths. This API hides this by putting the
initialization into the callee (PyObject_GetAttrId and friends),
hence the (unlikely) failure to initialize the string is reported in
the same code path as the (very plausible) error that the actual
attribute access failed.

Regards,
Martin


More information about the Python-Dev mailing list