-
-
Notifications
You must be signed in to change notification settings - Fork 34.3k
gh-143715: Deprecate incomplete initialization of struct.Struct() #145580
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 1 commit
fff147f
d2a0345
589fbc7
5e91e87
babb274
0e4e84b
3f36635
e576475
628aadd
979cc18
f7492ec
db8f5f2
dc8cbef
6206ae1
12143d1
d4ca6b8
6b9b4fb
79961a2
58550c0
c815882
f1388ee
685a6c4
76f8723
538d301
09d6ebd
7f0a133
26cde89
7697820
05eb292
d9c0488
3de045b
ebcf358
e003dab
d453990
66dbc04
6d60b16
d7da0f8
ca960a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -880,20 +880,28 @@ def __new__(cls, *args, **kwargs): | |
| return super().__new__(cls, '>h') | ||
|
|
||
| my_struct = MyStruct('>h') | ||
| self.assertEqual(my_struct.format, '>h') | ||
| self.assertEqual(my_struct.pack(12345), b'\x30\x39') | ||
| my_struct = MyStruct('<h') | ||
| self.assertEqual(my_struct.format, '>h') | ||
| self.assertEqual(my_struct.pack(12345), b'\x30\x39') | ||
| my_struct = MyStruct(format='<h') | ||
| self.assertEqual(my_struct.format, '>h') | ||
| self.assertEqual(my_struct.pack(12345), b'\x30\x39') | ||
| my_struct = MyStruct() | ||
| self.assertEqual(my_struct.format, '>h') | ||
| self.assertEqual(my_struct.pack(12345), b'\x30\x39') | ||
| my_struct = MyStruct(42) | ||
| self.assertEqual(my_struct.format, '>h') | ||
| self.assertEqual(my_struct.pack(12345), b'\x30\x39') | ||
| my_struct = MyStruct('$') | ||
| self.assertEqual(my_struct.format, '>h') | ||
| self.assertEqual(my_struct.pack(12345), b'\x30\x39') | ||
| my_struct = MyStruct('\u20ac') | ||
| self.assertEqual(my_struct.format, '>h') | ||
| self.assertEqual(my_struct.pack(12345), b'\x30\x39') | ||
| my_struct = MyStruct('<h', 42) | ||
| self.assertEqual(my_struct.format, '>h') | ||
| self.assertEqual(my_struct.pack(12345), b'\x30\x39') | ||
|
|
||
| def test_custom_struct_new_and_init(self): | ||
|
|
@@ -906,6 +914,7 @@ def __init__(self, newargs, initargs): | |
| super().__init__(*initargs) | ||
|
|
||
| my_struct = MyStruct(('>h',), ('>h',)) | ||
|
Comment on lines
+904
to
+912
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. Again, why no warnings here? BTW, I doubt this usage pattern come from reality ;-)
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. Because As for other cases, having both custom |
||
| self.assertEqual(my_struct.format, '>h') | ||
| self.assertEqual(my_struct.pack(12345), b'\x30\x39') | ||
| with self.assertRaises(TypeError): | ||
| MyStruct((), ()) | ||
|
|
@@ -930,15 +939,18 @@ def __init__(self, newargs, initargs): | |
| MyStruct(('>h',), ('\u20ac',)) | ||
| with self.assertWarns(FutureWarning): | ||
| my_struct = MyStruct(('>h',), ('<h',)) | ||
| self.assertEqual(my_struct.format, '<h') | ||
| self.assertEqual(my_struct.pack(12345), b'\x39\x30') | ||
|
|
||
| def test_no_custom_struct_new_or_init(self): | ||
| class MyStruct(struct.Struct): | ||
| pass | ||
|
|
||
| my_struct = MyStruct('>h') | ||
| self.assertEqual(my_struct.format, '>h') | ||
| self.assertEqual(my_struct.pack(12345), b'\x30\x39') | ||
| my_struct = MyStruct(format='>h') | ||
| self.assertEqual(my_struct.format, '>h') | ||
| self.assertEqual(my_struct.pack(12345), b'\x30\x39') | ||
| with self.assertRaises(TypeError): | ||
| MyStruct() | ||
|
|
||
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.
You can factorize some tests using ony 1 positional argument: