New submission from Neil Schemenauer: While poking around at bytes() related things, I noticed that the tp_richcompare method for bytes does not use the tp_as_buffer interface. Making it use it is quite easy, probably even makes the code simpler and faster. However, using it would mean that you could compare by bytes() and bytearray() to any object that implemented tp_as_buffer. I'm not sure about the whole implications of that. I tried changing it and found that a test failed for memoryview. The unit test expects TypeError from memoryview if you try to order them, e.g. >>> memoryview(b'a') < b'b' ... TypeError: unorderable types: memoryview() > bytes() >>> memoryview(b'a') < memoryview(b'b') ... TypeError: unorderable types: memoryview() > memoryview() That's inconsistent though, since bytearray does use tp_as_buffer: >>> memoryview(b'a') < bytearray(b'b') True I think we should make bytes() use tp_as_buffer. Attached is a patch that implements the idea. Needs some thought and review yet.
---------- files: cmp_buffer.patch keywords: patch messages: 208726 nosy: nascheme priority: low severity: normal stage: patch review status: open title: Make bytes() use tp_as_buffer for cmp type: enhancement versions: Python 3.5 Added file: http://bugs.python.org/file33603/cmp_buffer.patch _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue20339> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com