Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
bpo-43916: Apply Py_TPFLAGS_DISALLOW_INSTANTIATION to selected types#25748
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -6,7 +6,7 @@ | ||
| import tempfile | ||
| import unittest | ||
| from test.support import requires, verbose, SaveSignals | ||
| from test.support import requires, verbose, SaveSignals, cpython_only | ||
| from test.support.import_helper import import_module | ||
| # Optionally test curses module. This currently requires that the | ||
| @@ -1046,8 +1046,10 @@ def __del__(self): | ||
| panel.set_userptr(A()) | ||
| panel.set_userptr(None) | ||
| @cpython_only | ||
| @requires_curses_func('panel') | ||
| def test_new_curses_panel(self): | ||
| def test_disallow_instantiation(self): | ||
| # Ensure that the type disallows instantiation (bpo-43916) | ||
| w = curses.newwin(10, 10) | ||
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 also guess that the constructor would expect an argument: | ||
| panel = curses.panel.new_panel(w) | ||
| self.assertRaises(TypeError, type(panel)) | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,5 +1,5 @@ | ||||||
| from test import support | ||||||
| from test.support import import_helper | ||||||
| from test.support import import_helper, cpython_only | ||||||
| gdbm = import_helper.import_module("dbm.gnu") #skip if not supported | ||||||
| import unittest | ||||||
| import os | ||||||
| @@ -27,6 +27,13 @@ def tearDown(self): | ||||||
| self.g.close() | ||||||
| unlink(filename) | ||||||
| @cpython_only | ||||||
| def test_disallow_instantiation(self): | ||||||
| # Ensure that the type disallows instantiation (bpo-43916) | ||||||
| self.g = gdbm.open(filename, 'c') | ||||||
| tp = type(self.g) | ||||||
| self.assertRaises(TypeError, tp) | ||||||
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. Suggested change
| ||||||
| def test_key_methods(self): | ||||||
| self.g = gdbm.open(filename, 'c') | ||||||
| self.assertEqual(self.g.keys(), []) | ||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -948,6 +948,12 @@ class TestCmpToKeyC(TestCmpToKey, unittest.TestCase): | ||||||
| if c_functools: | ||||||
| cmp_to_key = c_functools.cmp_to_key | ||||||
| @support.cpython_only | ||||||
| def test_disallow_instantiation(self): | ||||||
| # Ensure that the type disallows instantiation (bpo-43916) | ||||||
| tp = type(c_functools.cmp_to_key(None)) | ||||||
| self.assertRaises(TypeError, tp) | ||||||
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. Suggested change
| ||||||
| class TestCmpToKeyPy(TestCmpToKey, unittest.TestCase): | ||||||
| cmp_to_key = staticmethod(py_functools.cmp_to_key) | ||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -2215,6 +2215,15 @@ def test_signedness(self): | ||||||
| self.assertGreaterEqual(sre_compile.MAXREPEAT, 0) | ||||||
| self.assertGreaterEqual(sre_compile.MAXGROUPS, 0) | ||||||
| @cpython_only | ||||||
| def test_disallow_instantiation(self): | ||||||
| # Ensure that the type disallows instantiation (bpo-43916) | ||||||
| self.assertRaises(TypeError, re.Match) | ||||||
| self.assertRaises(TypeError, re.Pattern) | ||||||
| pat = re.compile("") | ||||||
| tp = type(pat.scanner("")) | ||||||
| self.assertRaises(TypeError, tp) | ||||||
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. Suggested change
| ||||||
| class ExternalTests(unittest.TestCase): | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -736,8 +736,11 @@ def check(value): | ||
| check('{\n') | ||
| check('}\n') | ||
| @support.cpython_only | ||
| def test_new_tcl_obj(self): | ||
| self.assertRaises(TypeError, _tkinter.Tcl_Obj) | ||
erlend-aasland marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| self.assertRaises(TypeError, _tkinter.TkttType) | ||
| self.assertRaises(TypeError, _tkinter.TkappType) | ||
| class BigmemTclTest(unittest.TestCase): | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -119,6 +119,13 @@ def func(): pass | ||
| thread = threading.Thread(target=func) | ||
| self.assertEqual(thread.name, "Thread-5 (func)") | ||
| @cpython_only | ||
| def test_disallow_instantiation(self): | ||
| # Ensure that the type disallows instantiation (bpo-43916) | ||
| lock = threading.Lock() | ||
| tp = type(lock) | ||
| self.assertRaises(TypeError, tp) | ||
erlend-aasland marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| # Create a bunch of threads, let each do some work, wait until all are | ||
| # done. | ||
| def test_various_ops(self): | ||
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.
If it would expect, the constructor would expect an argument:
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.
Hm, I don't think so.
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.
Ditto for the similar suggestions.
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.
On what do you want to iterate if there is no argument?
Obviously, today, it takes no argument... because the type doesn't implement tp_new nor tp_init ;-)
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.
Does it really have anything to say? We hit the right exception anyway, AFAICS.
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.
My concern can be addressed later by adding an helper function which checks the error message.
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.
I insist on this issue because test_sys had a test which still passed when I modified sys.flags type to allow instantiation. I had to fix the test: 3bb0994
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.
Ah, I got it now. I misunderstood you first. Yes, that makes sense. We'll fix it when we've got a helper in place.