-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-30193: Allow to load buffer objects with json.loads() #14977
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
bpo-30193: Allow to load buffer objects with json.loads() #14977
Conversation
Co-authored-by: Nikolay Kim <fafhrd91@gmail.com>
@nascheme Fixed! |
Hi @flavianh , Thanks for your contribution! I think it is better to carry on your changes on the earlier pull request ( in order to keep track of the reviews and changes). It is difficult to hop on to different pull requests and referring to what actually has been already reviewed & addressed. In case you prefer rebasing, you can do a force push to update your branch and that should update your old PR. |
Have @serhiy-storchaka's comments from the bug tracker been addressed? |
Requesting reviews from those who had commented on the original PR. |
raise TypeError('the JSON object must be str, bytes or ' | ||
'bytearray or memoryview compatible object, ' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
raise TypeError('the JSON object must be str, bytes or ' | |
'bytearray or memoryview compatible object, ' | |
raise TypeError('the JSON object must be str, bytes, ' | |
'bytearray, or a memoryview-compatible object, ' |
self.assertEqual(self.loads(data), {"key": "val"}) | ||
|
||
def test_buffer(self): | ||
data = array.array('B') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use different encodings with BOM. Test also with array.array('H')
.
@@ -20,6 +21,15 @@ def test_empty_objects(self): | |||
self.assertEqual(self.loads('[]'), []) | |||
self.assertEqual(self.loads('""'), "") | |||
|
|||
def test_memoryview(self): | |||
data = memoryview(b'{"key": "val"}') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use different encodings with BOM. Test also with memoryview(...).cast('H')
.
Revival of #1334 updated to current master
https://bugs.python.org/issue30193