A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2002-September/028926.html below:

[Python-Dev] No __mod__ on str?

[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



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4