-
- Notifications
You must be signed in to change notification settings - Fork 33.4k
bpo-31315: Fix an assertion failure in imp.create_dynamic(), when spec.name is not a string #3257
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
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 |
|---|---|---|
| | @@ -21,6 +21,12 @@ def requires_load_dynamic(meth): | |
| meth = support.cpython_only(meth) | ||
| return unittest.skipIf(not hasattr(imp, 'load_dynamic'), | ||
| 'imp.load_dynamic() required')(meth) | ||
| def requires_create_dynamic(meth): | ||
| """Decorator to skip a test if not running under CPython or lacking | ||
| imp.create_dynamic().""" | ||
| ||
| meth = support.cpython_only(meth) | ||
| return unittest.skipIf(not hasattr(imp, 'create_dynamic'), | ||
| 'imp.create_dynamic() required')(meth) | ||
| ||
| | ||
| | ||
| @unittest.skipIf(_thread is None, '_thread module is required') | ||
| | @@ -318,6 +324,16 @@ def test_load_source(self): | |
| with self.assertRaisesRegex(ValueError, 'embedded null'): | ||
| imp.load_source(__name__, __file__ + "\0") | ||
| | ||
| @requires_create_dynamic | ||
| def test_issue31315(self): | ||
| # There shouldn't be an assertion failure in imp.create_dynamic(), | ||
| # when spec.name is not a string. | ||
| class BadSpec: | ||
| name = 42 | ||
| ||
| origin = 'foo' | ||
| 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. If origin is not a string SystemError can be raised. This should be fixed too. Contributor 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. what code causes a SystemError? 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. Your are right. I thought | ||
| with self.assertRaises(TypeError): | ||
| imp.create_dynamic(BadSpec()) | ||
| | ||
| | ||
| class ReloadTests(unittest.TestCase): | ||
| | ||
| | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Fix an assertion failure in imp.create_dynamic(), when spec.name is not a | ||
| string. Patch by Oren Milman. |
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.
Readability improvement: blank line before the function