This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Make bytes() use tp_as_buffer for cmp
Type: enhancement Stage: patch review
Components: Interpreter Core Versions: Python 3.5
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: fin.swimmer, flox, nascheme, ncoghlan, skrah
Priority: low Keywords: patch

Created on 2014-01-22 00:40 by nascheme, last changed 2022-04-11 14:57 by admin.

Files
File name Uploaded Description Edit
cmp_buffer.patch nascheme, 2014-01-22 00:40
Messages (3)
msg208726 - (view) Author: Neil Schemenauer (nascheme) * (Python committer) Date: 2014-01-22 00:40
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.
msg209352 - (view) Author: fin swimmer (fin.swimmer) Date: 2014-01-26 20:48
This is exactly what I need!

Would be a great work.
msg229304 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2014-10-14 15:39
The comparisons can be somewhat meaningless though:

>>> from _testbuffer import *
>>> x = ndarray([1.1, 2.2, 3.3, 4.4, 5.5, 6.6], shape=[2,3], format="f")
>>> x.tolist()
[[1.100000023841858, 2.200000047683716, 3.299999952316284], [4.400000095367432, 5.5, 6.599999904632568]]
>>> memoryview(x) < bytearray(b'b')
False
History
Date User Action Args
2022-04-11 14:57:57adminsetgithub: 64538
2014-10-14 15:39:03skrahsetmessages: + msg229304
2014-01-26 20:48:35fin.swimmersetnosy: + fin.swimmer
messages: + msg209352
2014-01-22 13:44:43pitrousetnosy: + ncoghlan, skrah
2014-01-22 01:12:34floxsetnosy: + flox
components: + Interpreter Core
2014-01-22 00:40:29naschemecreate