gh-119560: Drop an Invalid Assert in PyState_FindModule() (gh-119561)

The assertion was added in gh-118532 but was based on the invalid assumption that PyState_FindModule() would only be called with an already-initialized module def.  I've added a test to make sure we don't make that assumption again.
This commit is contained in:
Eric Snow 2024-05-25 15:30:48 -04:00 committed by GitHub
parent 4b7eb321bc
commit 0c5ebe13e9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 100 additions and 4 deletions

View file

@ -2887,6 +2887,13 @@ class SinglephaseInitTests(unittest.TestCase):
self.assertIs(reloaded.snapshot.cached, reloaded.module)
def test_check_state_first(self):
for variant in ['', '_with_reinit', '_with_state']:
name = f'{self.NAME}{variant}_check_cache_first'
with self.subTest(name):
mod = self._load_dynamic(name, self.ORIGIN)
self.assertEqual(mod.__name__, name)
# Currently, for every single-phrase init module loaded
# in multiple interpreters, those interpreters share a
# PyModuleDef for that object, which can be a problem.