On Tue, Aug 17, 2010 at 11:11 PM, Stefan Behnel <[email protected]> wrote:
> Robert Bradshaw, 18.08.2010 06:27:
> > Perhaps we should control this with a flag.
>
> I'm not a big fan at all of changing behaviour with flags, but I'm strictly
> against doing it in cases where the resulting behaviour is not obvious.
> It's absolutely not obvious to me that a flag to make a call to a regular
> Python special method faster makes that method unavailable from Python
> code. Such an impact is too easy to get missed by tests.
More possibilities: control __getattr__ by a special declaration, that
is either required (is this possible?) or strongly encouraged to be
placed directly on the __getattr__ method rather than scoped over a
larger area. (Surely we could come up with a name that addresses
Stefan's concerns?
@cython.make_fast_getattr_that_is_unavailable_to_python ?)
Another option: add a decorator so that instead of:
def __getattr__(self, attr):
# your code here
you can equivalently write:
@cython.getattr_semantics_for_getattribute
def __getattribute__(self, attr):
# your code here
and have it mean the same thing. For Cython, this would mean
generating essentially the same C code we already put in tp_getattro:
PyObject *v = PyObject_GenericGetAttr(o, n);
if (!v && PyErr_ExceptionMatches(PyExc_AttributeError)) {
PyErr_Clear();
v = # your code here
}
but for Python this could be done as a regular decorator, although the
result would be slow.
Although I'm actually in favor of just leaving the post-#561 status,
where __getattr__ remains unavailable to Python, using the "cdef
classes are different" rationale.
Carl
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev