[issue44439] PickleBuffer doesn't have __len__ method

2021-06-17 Thread Ma Lin


Change by Ma Lin :


--
keywords: +patch
pull_requests: +25350
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/26764

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44439] PickleBuffer doesn't have __len__ method

2021-06-17 Thread Ma Lin


Ma Lin  added the comment:

Ok, I'm working on a PR.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44439] PickleBuffer doesn't have __len__ method

2021-06-16 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

Oh, LZMAFile.write() should not use len() directly on input data because it 
does not always work correctly with memoryview and other objects supporting the 
buffer protocol. It should use memoryview(data).nbytes or data = 
memoryview(data).cast('B') if other byte-oriented operations (indexing, 
slicing) are used. See for example Lib/gzip.py, Lib/_pyio.py, 
Lib/_compression.py, Lib/ssl.py, Lib/socketserver.py, Lib/wave.py.

--
nosy: +nadeem.vawda, serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44439] PickleBuffer doesn't have __len__ method

2021-06-16 Thread Ma Lin


New submission from Ma Lin :

If run this code, it will raise an exception: 

import pickle
import lzma
import pandas as pd
with lzma.open("test.xz", "wb") as file:
pickle.dump(pd.DataFrame(range(1_000_000)), file, protocol=5)

The exception:

Traceback (most recent call last):
  File "E:\testlen.py", line 7, in 
pickle.dump(pd.DataFrame(range(1_000_000)), file, protocol=5)
  File "D:\Python39\lib\lzma.py", line 234, in write
self._pos += len(data)
TypeError: object of type 'pickle.PickleBuffer' has no len()

The exception is raised in lzma.LZMAFile.write() method:
https://github.com/python/cpython/blob/v3.10.0b2/Lib/lzma.py#L238

PickleBuffer doesn't have .__len__ method, is it intended?

--
messages: 395971
nosy: malin, pitrou
priority: normal
severity: normal
status: open
title: PickleBuffer doesn't have __len__ method

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com