Title: bytearray incompatible with y#
Type: behavior Stage:
Components: Documentation Versions: Python 3.0, Python 2.6
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: Frostburn, georg.brandl, pitrou
Priority: normal Keywords:

Created on 2008-09-01 16:03 by Frostburn, last changed 2019-08-01 15:53 by vstinner. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 14679 closed nanjekyejoannah, 2019-07-16 16:16
PR 14679 closed nanjekyejoannah, 2019-07-16 16:16
PR 15072 open vstinner, 2019-08-01 15:53
Messages (3)
msg72266 - (view) Author: Pyry Pakkanen (Frostburn) Date: 2008-09-01 16:03
I was expecting that the API function PyArg_ParseTuple(args, "y#:foo",
&cp, &size) would accept a bytearray and implicitly convert it to bytes.
Currently it throws the error:
TypeError: foo() argument 1 must be bytes or read-only buffer, not bytearray
msg72270 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2008-09-01 16:17
Yes, you must use y* instead: see

y# would not be safe to use with bytearray since another thread could
mutate the bytearray in-between, possibly reallocating the internal
buffer (to shrink or grow it), and lead to a segfault when your thread
uses the obsolete pointer.

IMO, the documentation should mention that the '*' codes (y*, s*, etc.)
must be used in preference to the '#' codes, which are there for
backwards compatibility.
msg72273 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2008-09-01 16:45
Documented in r66113.
Date User Action Args
2019-08-01 15:53:55vstinnersetpull_requests: + pull_request14819
2019-07-16 16:16:40nanjekyejoannahsetpull_requests: + pull_request14591
2019-07-16 16:16:40nanjekyejoannahsetpull_requests: + pull_request14590
2019-07-11 15:27:08ZackerySpytzsetpull_requests: - pull_request14485
2019-07-09 19:36:49nanjekyejoannahsetpull_requests: + pull_request14485
2008-09-01 16:45:49georg.brandlsetstatus: open -> closed
resolution: fixed
messages: + msg72273
2008-09-01 16:17:12pitrousetversions: + Python 2.6
nosy: + georg.brandl, pitrou
title: bytearray incompatible with bytes -> bytearray incompatible with y#
messages: + msg72270
assignee: georg.brandl
components: + Documentation
2008-09-01 16:03:42Frostburncreate