[Python-Dev] No __mod__ on str?
Neil Schemenauer
nas@python.ca
Wed, 25 Sep 2002 14:51:25 -0700
Here's the code for PyNumber_Remainder:
PyObject *
PyNumber_Remainder(PyObject *v, PyObject *w)
{
if (PyString_Check(v))
return PyString_Format(v, w);
#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(v))
return PyUnicode_Format(v, w);
#endif
return binary_op(v, w, NB_SLOT(nb_remainder), "%");
}
Is there any good reason why str.__mod__ != PyString_Format? I want to
make a subclass of str that overrides the format operator. I guess one
side effect would be that PyNumber_Check(astring) would start returning
true.
Should I file a bug saying "can't override __mod__ on str and unicode
subclasses"? I guess the fix would be to check for nb_remainder first
and then fallback to PyString_Format or PyUnicode_Format.
Neil