GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — bpo-31285: fix an assertion failure and a SystemError in warnings.warn_explicit by orenmn · Pull Request #3219 · python/cpython Conversation
|
|
|
||
| /* Split the source into lines. */ | ||
| source_list = PyObject_CallMethodObjArgs(source, | ||
| source_list = PyObject_CallMethodObjArgs((PyObject *)&PyUnicode_Type, |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Use just PyUnicode_Splitlines().
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| return splitlines_ret_val | ||
| return BadSource() | ||
| return BadLoader() | ||
| self.assertRaises(IndexError, self.module.warn_explicit, |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Since this test already takes multiple lines, I think it would look clearer if use a context manager form:
with self.assertRaises(IndexError):
self.module.warn_explicit(...)
But why IndexError is expected? Wouldn't be better to test the normal case that doesn't raise an error? You can use test.support.captured_stderr() for capturing the warning output.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| self.assertNotIn(b'Warning!', stderr) | ||
| self.assertNotIn(b'Error', stderr) | ||
|
|
||
| def test_warn_explicit(self): |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This name is too general, but the test isn't a general test of warn_explicit(). Use something more specific like test_issue31285.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| 'foo', UserWarning, 'bar', 1, | ||
| module_globals={'__loader__': _get_bad_loader(42), | ||
| '__name__': 'foobar'}) | ||
| self.assertIn('bar:1: UserWarning: foo', stderr.getvalue()) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I am not sure whether this and the other call to assertIn() are necessary, as we want to make sure a SystemError and an assertion failure don't happen...
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| # warn_explicit() should neither raise a SystemError nor cause an | ||
| # assertion failure, in case the return value of get_source() has a | ||
| # bad splitlines() method. | ||
| def _get_bad_loader(splitlines_ret_val): |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Starting underscore is not needed.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| del self.module._showwarnmsg | ||
| with support.captured_stderr() as stderr: | ||
| self.module.warn_explicit( | ||
| 'foo', ArithmeticError, 'bar', 1, |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Is it valid to use ArithmeticError which is not a warning category?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
It is valid (IIUC, only warning.warns() requires the category to be a subclass of Warning). I used ArithmeticError because it caused get_filter() to return 'default'. But now it seems quite obscure to me, so I would change it.
Also, my test fails with -Werror, so I would fix that too.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks @orenmn for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 2.7, 3.6. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Sorry, @orenmn and @serhiy-storchaka, I could not cleanly backport this to |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks @orenmn for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 2.7, 3.6. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Sorry @orenmn and @serhiy-storchaka, I had trouble checking out the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Sorry, @orenmn and @serhiy-storchaka, I could not cleanly backport this to |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…gs.warn_explicit. (pythonGH-3219) (cherry picked from commit 91fb0af)
|
GH-3775 is a backport of this pull request to the 3.6 branch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
GH-3805 is a backport of this pull request to the 2.7 branch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…pythonGH-3803) (forgot to remove it in pythonGH-3219) (cherry picked from commit 8b4ff53)
…) in case __loader__.get_source() has a bad splitlines() method. (pythonGH-3219)
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.