Issue2784

classification
Title: memoryview accepts unicode strings as input
Type: behaviour Severity: normal
Components: Core Versions: Jython 2.7
Milestone: Jython 2.7.2
process
Status: pending Resolution: duplicate
Dependencies: Restrict array.array support for buffer protocol
View: 2715
Superseder:
Assigned To: Nosy List: behackett, jeff.allen
Priority: Keywords:

Created on 2019-07-17.23:53:41 by behackett, last changed 2019-07-21.07:07:54 by jeff.allen.

Messages
msg12578 (view) Author: Bernie Hackett (behackett) Date: 2019-07-17.23:53:41
In CPython 2 and 3 and PyPy 2 and 3 memoryview only accepts objects that implement the buffer protocol. unicode / python3 str don't implement the buffer protocol so memoryview doesn't accept them, but memoryview in Jython does.

Jython 2.7.0 (default:9987c746f838, Apr 29 2015, 02:25:11) 
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.8.0_202
Type "help", "copyright", "credits" or "license" for more information.
>>> memoryview(u"foobar").tobytes()
'foobar'

Python 3.6.9 (default, Jul 17 2019, 12:02:47) 
[GCC 9.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> memoryview(u"foobar").tobytes()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: memoryview: a bytes-like object is required, not 'str'
>>> 

Python 2.7.16 (default, Mar  6 2019, 09:58:35) 
[GCC 8.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> memoryview(u"foobar").tobytes()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: cannot make memory view because object does not have the buffer interface
msg12600 (view) Author: Jeff Allen (jeff.allen) Date: 2019-07-21.07:07:54
I'm happy to report that's fixed, as a result of work on #2715. 2.7.2a1 currently does this:

>>> memoryview(u"foobar")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: cannot make memory view because object does not have the buffer interface
History
Date User Action Args
2019-07-21 07:07:54jeff.allensetstatus: open -> pending
nosy: + jeff.allen
messages: + msg12600
dependencies: + Restrict array.array support for buffer protocol
milestone: Jython 2.7.2
resolution: duplicate
2019-07-17 23:53:41behackettcreate