On 19 April 2015 at 01:37, Ionel Cristian Mărieș <contact@ionelmc.ro> wrote:
Sorry, I pasted a patch with changes unrelated to this discussion. This is the gist of the proposed change:

 int
 PyCallable_Check(PyObject *x)
 {
     if (x == NULL)
         return 0;
-    return x->ob_type->tp_call;
+    return x->ob_type->tp_call && _PyObject_HasAttrId(x, &PyId___call__);
 }


OK, thanks. I'd say that doesn't need a PEP. But because it makes callable() a bit slower, and means that it can execute arbitrary Python code where it doesn't at the moment, for a pretty small gain (a few rare cases will no longer give a "false positive" result from callable(), but other false positives could well still exist), I can imagine the change being rejected based on the benefits not justifying the cost.

Personally, I don't often use callable(). So I don't have a strong opinion. But when I *do* use it, it's because I want to check if something is callable *without* calling it - so the fact that callable() doesn't run arbitrary code is relevant to me. And the motivating use cases (__call__ being a property on the class object) seem pretty obscure - I've never encountered anything like that in real life. So overall, I'd be -0 on the change.

Paul