-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
gh-142037: Improve error messages for printf-style formatting #142081
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 7 commits
c5b1321
8d9d009
c52feb2
0e43000
c015d6a
4e5538b
cb7ea11
380157d
8aa1920
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1578,17 +1578,17 @@ def __int__(self): | |
| self.assertEqual('%X' % letter_m, '6D') | ||
| self.assertEqual('%o' % letter_m, '155') | ||
| self.assertEqual('%c' % letter_m, 'm') | ||
| self.assertRaisesRegex(TypeError, '%x format: an integer is required, not float', operator.mod, '%x', 3.14) | ||
| self.assertRaisesRegex(TypeError, '%X format: an integer is required, not float', operator.mod, '%X', 2.11) | ||
| self.assertRaisesRegex(TypeError, '%o format: an integer is required, not float', operator.mod, '%o', 1.79) | ||
| self.assertRaisesRegex(TypeError, '%x format: an integer is required, not PseudoFloat', operator.mod, '%x', pi) | ||
| self.assertRaisesRegex(TypeError, '%x format: an integer is required, not complex', operator.mod, '%x', 3j) | ||
| self.assertRaisesRegex(TypeError, '%X format: an integer is required, not complex', operator.mod, '%X', 2j) | ||
| self.assertRaisesRegex(TypeError, '%o format: an integer is required, not complex', operator.mod, '%o', 1j) | ||
| self.assertRaisesRegex(TypeError, '%u format: a real number is required, not complex', operator.mod, '%u', 3j) | ||
| self.assertRaisesRegex(TypeError, '%i format: a real number is required, not complex', operator.mod, '%i', 2j) | ||
| self.assertRaisesRegex(TypeError, '%d format: a real number is required, not complex', operator.mod, '%d', 1j) | ||
| self.assertRaisesRegex(TypeError, r'%c requires an int or a unicode character, not .*\.PseudoFloat', operator.mod, '%c', pi) | ||
| self.assertRaisesRegex(TypeError, '%x requires an integer, not float', operator.mod, '%x', 3.14) | ||
|
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. I would prefer to check also the
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. I am not sure that it is related to the purpose of this test, but I'll do this. Although it make the lines obscenely long. |
||
| self.assertRaisesRegex(TypeError, '%X requires an integer, not float', operator.mod, '%X', 2.11) | ||
| self.assertRaisesRegex(TypeError, '%o requires an integer, not float', operator.mod, '%o', 1.79) | ||
| self.assertRaisesRegex(TypeError, r'%x requires an integer, not .*\.PseudoFloat', operator.mod, '%x', pi) | ||
| self.assertRaisesRegex(TypeError, '%x requires an integer, not complex', operator.mod, '%x', 3j) | ||
| self.assertRaisesRegex(TypeError, '%X requires an integer, not complex', operator.mod, '%X', 2j) | ||
| self.assertRaisesRegex(TypeError, '%o requires an integer, not complex', operator.mod, '%o', 1j) | ||
| self.assertRaisesRegex(TypeError, '%u requires a real number, not complex', operator.mod, '%u', 3j) | ||
| self.assertRaisesRegex(TypeError, '%i requires a real number, not complex', operator.mod, '%i', 2j) | ||
| self.assertRaisesRegex(TypeError, '%d requires a real number, not complex', operator.mod, '%d', 1j) | ||
| self.assertRaisesRegex(TypeError, r'%c requires an integer or a unicode character, not .*\.PseudoFloat', operator.mod, '%c', pi) | ||
|
|
||
| class RaisingNumber: | ||
| def __int__(self): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| Improve error messages for printf-style formatting. | ||
| For errors in the format string, always include the position of the | ||
| start of the format unit. | ||
| For errors related to the formatted arguments, always include the number | ||
| or the name of the argument. | ||
| Raise more specific errors and include more information (type and number | ||
| of arguments, most probable causes of error). |
Uh oh!
There was an error while loading. Please reload this page.