Hi everywhere.
I decided to figure out why it is impossible to change methods of built-in 
types and found 
```
    if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE)) {
        PyErr_Format(
            PyExc_TypeError,
            "can't set attributes of built-in/extension type '%s'",
            type->tp_name);
        return -1;
    }
```
in function type_setattro. 
If comment this line and try to patch method __eq__ on the list for example the 
code will work as expected

Test:
```
with patch("builtins.list.__eq__", return_value=False):
    assert [] == []
```
Result: `AssertionError` as expected. Is there a real need to disallow patching 
of built-in types or is it just legacy?
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/FYS52CPAN7EMSQF4WF3WM5VNO52TBOIT/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to