-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
gh-78724: raise RuntimeError's when calling methods on non-ready Struct()'s #143643
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 11 commits
a1c2603
716e28c
e611953
ab62167
3b18427
54dbea8
b6c8bed
f542173
69a5eec
0e6af95
8ba6b33
ea0f8e2
c71be45
b61bddb
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 |
|---|---|---|
|
|
@@ -816,6 +816,18 @@ def test_endian_table_init_subinterpreters(self): | |
| results = executor.map(exec, [code] * 5) | ||
| self.assertListEqual(list(results), [None] * 5) | ||
|
|
||
| def test_operations_on_half_initialized_Struct(self): | ||
| S = struct.Struct.__new__(struct.Struct) | ||
|
|
||
| spam = array.array('b', b' ') | ||
| self.assertRaises(RuntimeError, S.iter_unpack, 1) | ||
| self.assertRaises(RuntimeError, S.pack, 1) | ||
| self.assertRaises(RuntimeError, S.pack_into, 1) | ||
|
Member
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.
Member
Author
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. BTW, I think that argument processing in the struct's functions/methods should be refactored and transformed to the AC. E.g. S.pack_info could check required arguments before validation of the soself struct. Though, this belongs to a separate issue.
Member
Author
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. AC cleanup goes to #143673 |
||
| self.assertRaises(RuntimeError, S.unpack, spam) | ||
| self.assertRaises(RuntimeError, S.unpack_from, spam) | ||
| self.assertRaises(RuntimeError, getattr, S, 'format') | ||
| self.assertEqual(S.size, -1) | ||
|
|
||
|
|
||
| class UnpackIteratorTest(unittest.TestCase): | ||
| """ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Raise :exc:`RuntimeError`'s when user attempts to call methods on | ||
| half-initialized :class:`~struct.Struct` objects, For example, created by | ||
| ``Struct.__new__(Struct)``. Patch by Sergey B Kirpichev. |
Uh oh!
There was an error while loading. Please reload this page.