8000 bpo-35381 Remove all static state from posixmodule (GH-15892) · python/cpython@b396663 · GitHub
[go: up one dir, main page]

Skip to content

Commit b396663

Browse files
eduardo-elizondomiss-islington
authored andcommitted
bpo-35381 Remove all static state from posixmodule (GH-15892)
After #9665, this moves the remaining types in posixmodule to be heap-allocated to make it compatible with PEP384 as well as modifying all the type accessors to fully make the type opaque. The original PR that got messed up a rebase: #10854. All the issues in that commit have now been addressed since #11661 got committed. This change also removes any state from the data segment and onto the module state itself. https://bugs.python.org/issue35381 Automerge-Triggered-By: @encukou
1 parent 5e01a65 commit b396663

File tree

4 files changed

+305
-226
lines changed

4 files changed

+305
-226
lines changed

Lib/test/test_os.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3638,6 +3638,24 @@ def test_os_all(self):
36383638
self.assertIn('walk', os.__all__)
36393639

36403640

3641+
class TestDirEntry(unittest.TestCase):
3642+
def setUp(self):
3643+
self.path = os.path.realpath(support.TESTFN)
3644+
self.addCleanup(support.rmtree, self.path)
3645+
os.mkdir(self.path)
3646+
3647+
def test_uninstantiable(self):
3648+
self.assertRaises(TypeError, os.DirEntry)
3649+
3650+
def test_unpickable(self):
3651+
filename = create_file(os.path.join(self.path, "file.txt"), b'python')
3652+
entry = [entry for entry in os.scandir(self.path)].pop()
3653+
self.assertIsInstance(entry, os.DirEntry)
3654+
self.assertEqual(entry.name, "file.txt")
3655+
import pickle
3656+
self.assertRaises(TypeError, pickle.dumps, entry, filename)
3657+
3658+
36413659
class TestScandir(unittest.TestCase):
36423660
check_no_resource_warning = support.check_no_resource_warning
36433661

@@ -3672,6 +3690,18 @@ def assert_stat_equal(self, stat1, stat2, skip_fields):
36723690
else:
36733691
self.assertEqual(stat1, stat2)
36743692

3693+
def test_uninstantiable(self):
3694+
scandir_iter = os.scandir(self.path)
3695+
self.assertRaises(TypeError, type(scandir_iter))
3696+
scandir_iter.close()
3697+
3698+
def test_unpickable(self):
3699+
filename = self.create_file("file.txt")
3700+
scandir_iter = os.scandir(self.path)
3701+
import pickle
3702+
self.assertRaises(TypeError, pickle.dumps, scandir_iter, filename)
3703+
scandir_iter.close()
3704+
36753705
def check_entry(self, entry, name, is_dir, is_file, is_symlink):
36763706
self.assertIsInstance(entry, os.DirEntry)
36773707
self.assertEqual(entry.name, name)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Convert posixmodule.c statically allocated types ``DirEntryType`` and
2+
``ScandirIteratorType`` to heap-allocated types.

Modules/clinic/posixmodule.c.h

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
0