-
Notifications
You must be signed in to change notification settings - Fork 19
Drive zlib, binascii, and struct builtins off the __pyre_kw__ marker ABI #1123
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
Changes from all commits
6462483
6c0ced5
5a341ff
02a5fcb
4a806ef
fdef944
fe5d0d8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -102,3 +102,19 @@ def __index__(self): | |||||||||||||||||||||||||||||||||||||||||||||||||
| unpack_iterator_type = type(struct.iter_unpack("B", b"")) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| with assert_raises(TypeError): | ||||||||||||||||||||||||||||||||||||||||||||||||||
| unpack_iterator_type() | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| # unpack_from accepts buffer / offset positionally or by keyword. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| _buf = struct.pack("ii", 111, 222) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| assert struct.unpack_from("ii", _buf, offset=0) == (111, 222) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| assert struct.unpack_from("ii", buffer=_buf, offset=0) == (111, 222) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| _s = struct.Struct("ii") | ||||||||||||||||||||||||||||||||||||||||||||||||||
| assert _s.unpack_from(_buf, offset=0) == (111, 222) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| assert _s.unpack_from(buffer=_buf) == (111, 222) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+105
to
+112
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win Add the positional-only negative case for The block proves that 💚 Proposed additional case assert _s.unpack_from(buffer=_buf) == (111, 222)
+with assert_raises(TypeError):
+ struct.unpack_from(format="ii", buffer=_buf)📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| # pack / pack_into (module and method) reject keyword arguments. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| with assert_raises(TypeError): | ||||||||||||||||||||||||||||||||||||||||||||||||||
| struct.pack(format="ii") | ||||||||||||||||||||||||||||||||||||||||||||||||||
| with assert_raises(TypeError): | ||||||||||||||||||||||||||||||||||||||||||||||||||
| struct.pack_into("ii", bytearray(8), 0, 1, 2, extra=3) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| with assert_raises(TypeError): | ||||||||||||||||||||||||||||||||||||||||||||||||||
| _s.pack_into(bytearray(8), 0, 1, 2, extra=3) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+114
to
+120
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win Add cases for omitted required arguments. The new tests cover keyword rejection only. The binder pads omitted positionals with 💚 Proposed additional cases with assert_raises(TypeError):
_s.pack_into(bytearray(8), 0, 1, 2, extra=3)
+
+# pack / pack_into reject calls that omit required positional slots.
+with assert_raises(TypeError):
+ struct.pack()
+with assert_raises(TypeError):
+ struct.pack_into("ii", bytearray(8))
+with assert_raises(TypeError):
+ _s.pack_into()
+with assert_raises(TypeError):
+ _s.pack_into(bytearray(8))📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||
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.
📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win
Add the
load(file=...)assertion that the comment claims.The comment states that
bytesandfileare positional-only, but onlymarshal.loads(bytes=data)is tested. Add theloadcase so thefileboundary is covered.💚 Proposed test addition
# `bytes` / `file` are positional-only too. with self.assertRaises(TypeError): marshal.loads(bytes=data) + with self.assertRaises(TypeError): + marshal.load(file=BytesIO(data))Import
BytesIOin this test, astest_file_apidoes.🧰 Tools
🪛 ast-grep (0.45.0)
[warning] 115-115: dill and marshal deserialize arbitrary objects/bytecode and execute code on untrusted input. Use a safe serialization format and never load untrusted data.
Context: marshal.loads(bytes=data)
Note: [CWE-502] Deserialization of Untrusted Data.
(dill-marshal-deserialization-python)
🪛 OpenGrep (1.26.0)
[WARNING] 116-116: marshal.loads() can execute arbitrary code during deserialization. Use a safe format like JSON instead.
(coderabbit.deserialization.python-marshal)
🪛 Ruff (0.16.1)
[warning] 115-115: Use
pytest.raisesinstead of unittest-styleassertRaisesReplace
assertRaiseswithpytest.raises(PT027)
[error] 116-116: Deserialization with the
marshalmodule is possibly dangerous(S302)
🤖 Prompt for AI Agents