Skip to content

Commit 37b2774

Browse files
committed
Cleanup
1 parent ad7dfd2 commit 37b2774

File tree

3 files changed

+20
-27
lines changed

3 files changed

+20
-27
lines changed

Lib/test/datetimetester.py

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7155,8 +7155,8 @@ def test_datetime_from_timestamp(self):
71557155

71567156
self.assertEqual(dt_orig, dt_rt)
71577157

7158-
def assert_python_in_subinterp(self, check_if_ok, script, init='',
7159-
fini='', repeat=1, config='isolated'):
7158+
def assert_python_ok_in_subinterp(self, script, init='', fini='',
7159+
repeat=1, config='isolated'):
71607160
# iOS requires the use of the custom framework loader,
71617161
# not the ExtensionFileLoader.
71627162
if sys.platform == "ios":
@@ -7177,7 +7177,7 @@ def assert_python_in_subinterp(self, check_if_ok, script, init='',
71777177
spec = importlib.util.spec_from_loader(fullname, loader)
71787178
_testcapi = importlib.util.module_from_spec(spec)
71797179
spec.loader.exec_module(_testcapi)
7180-
INDEX = $INDEX$
7180+
run_counter = $RUN_COUNTER$
71817181
setup = _testcapi.test_datetime_capi_newinterp # call it if needed
71827182
$SCRIPT$
71837183
"""
@@ -7187,8 +7187,8 @@ def assert_python_in_subinterp(self, check_if_ok, script, init='',
71877187
setup = _testcapi.test_datetime_capi_newinterp
71887188
$INIT$
71897189
7190-
for idx in range({repeat}):
7191-
subcode = subinterp_code.replace('$INDEX$', str(idx))
7190+
for i in range(1, {1 + repeat}):
7191+
subcode = subinterp_code.replace('$RUN_COUNTER$', str(i))
71927192
if {_interpreters is None}:
71937193
ret = support.run_in_subinterp(subcode)
71947194
else:
@@ -7200,12 +7200,7 @@ def assert_python_in_subinterp(self, check_if_ok, script, init='',
72007200
''')
72017201
code = code.replace('$INIT$', init).replace('$FINI$', fini)
72027202
code = code.replace('$SCRIPT$', script)
7203-
7204-
if check_if_ok:
7205-
res = script_helper.assert_python_ok('-c', code)
7206-
else:
7207-
res = script_helper.assert_python_failure('-c', code)
7208-
return res
7203+
return script_helper.assert_python_ok('-c', code)
72097204

72107205
def test_type_check_in_subinterp(self):
72117206
script = textwrap.dedent(f"""
@@ -7221,10 +7216,10 @@ def run(type_checker, obj):
72217216
run(_testcapi.datetime_check_delta, _datetime.timedelta(1))
72227217
run(_testcapi.datetime_check_tzinfo, _datetime.tzinfo())
72237218
""")
7224-
self.assert_python_in_subinterp(True, script)
7219+
self.assert_python_ok_in_subinterp(script)
72257220
if _interpreters is not None:
72267221
with self.subTest(name := 'legacy'):
7227-
self.assert_python_in_subinterp(True, script, config=name)
7222+
self.assert_python_ok_in_subinterp(script, config=name)
72287223

72297224

72307225
class ExtensionModuleTests(unittest.TestCase):
@@ -7233,8 +7228,8 @@ def setUp(self):
72337228
if self.__class__.__name__.endswith('Pure'):
72347229
self.skipTest('Not relevant in pure Python')
72357230

7236-
def assert_python_in_subinterp(self, *args, **kwargs):
7237-
return CapiTest.assert_python_in_subinterp(self, *args, **kwargs)
7231+
def assert_python_ok_in_subinterp(self, *args, **kwargs):
7232+
return CapiTest.assert_python_ok_in_subinterp(self, *args, **kwargs)
72387233

72397234
@support.cpython_only
72407235
def test_gh_120161(self):
@@ -7337,25 +7332,25 @@ def test_static_type_on_subinterp(self):
73377332
""")
73387333
with_setup = 'setup()' + script
73397334
with self.subTest('[PyDateTime_IMPORT] main: no, sub: yes'):
7340-
self.assert_python_in_subinterp(True, with_setup)
7335+
self.assert_python_ok_in_subinterp(with_setup)
73417336

73427337
with self.subTest('[PyDateTime_IMPORT] main: yes, sub: yes'):
73437338
# Fails if the setup() means test_datetime_capi() rather than
73447339
# test_datetime_capi_newinterp()
7345-
self.assert_python_in_subinterp(True, with_setup, 'setup()')
7346-
self.assert_python_in_subinterp(True, 'setup()', fini=with_setup)
7347-
self.assert_python_in_subinterp(True, with_setup, repeat=2)
7340+
self.assert_python_ok_in_subinterp(with_setup, 'setup()')
7341+
self.assert_python_ok_in_subinterp('setup()', fini=with_setup)
7342+
self.assert_python_ok_in_subinterp(with_setup, repeat=2)
73487343

73497344
with_import = 'import _datetime' + script
73507345
with self.subTest('Explicit import'):
7351-
self.assert_python_in_subinterp(True, with_import, 'setup()')
7346+
self.assert_python_ok_in_subinterp(with_import, 'setup()')
73527347

73537348
with_import = textwrap.dedent("""
73547349
timedelta = _testcapi.get_capi_types()['timedelta']
73557350
timedelta(days=1)
73567351
""") + script
73577352
with self.subTest('Implicit import'):
7358-
self.assert_python_in_subinterp(True, with_import, 'setup()')
7353+
self.assert_python_ok_in_subinterp(with_import, 'setup()')
73597354

73607355
def test_static_type_at_shutdown(self):
73617356
# gh-132413
@@ -7383,7 +7378,7 @@ def gen():
73837378
res = script_helper.assert_python_ok('-c', script)
73847379
self.assertFalse(res.err)
73857380
with self.subTest('Subinterpreter'):
7386-
res = self.assert_python_in_subinterp(True, script)
7381+
res = self.assert_python_ok_in_subinterp(script)
73877382
self.assertFalse(res.err)
73887383

73897384
script = textwrap.dedent("""
@@ -7404,12 +7399,12 @@ def gen():
74047399
next(it)
74057400
""")
74067401
with self.subTest('[PyDateTime_IMPORT] main: yes, sub: no'):
7407-
res = self.assert_python_in_subinterp(True, script, 'setup()')
7402+
res = self.assert_python_ok_in_subinterp(script, 'setup()')
74087403
self.assertIn(b'ImportError: sys.meta_path is None', res.err)
74097404

74107405
with_import = 'setup()' + script
74117406
with self.subTest('[PyDateTime_IMPORT] main: no, sub: yes'):
7412-
res = self.assert_python_in_subinterp(True, with_import)
7407+
res = self.assert_python_ok_in_subinterp(with_import)
74137408
self.assertFalse(res.err)
74147409

74157410

Lib/test/test_embed.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ def gen():
458458
try:
459459
timedelta(days=1)
460460
res = 1
461-
except ImportError as e:
461+
except ImportError:
462462
res = 2
463463
print(res)
464464

Modules/_datetimemodule.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include "Python.h"
1313
#include "pycore_long.h" // _PyLong_GetOne()
1414
#include "pycore_object.h" // _PyObject_Init()
15-
#include "pycore_pylifecycle.h" // _Py_IsInterpreterFinalizing()
1615
#include "pycore_time.h" // _PyTime_ObjectToTime_t()
1716
#include "pycore_unicodeobject.h" // _PyUnicode_Copy()
1817

@@ -156,7 +155,6 @@ _get_current_state(PyObject **p_mod)
156155
* so we must re-import the module. */
157156
PyObject *mod = PyImport_ImportModule("_datetime");
158157
if (mod == NULL) {
159-
assert(_Py_IsInterpreterFinalizing(interp));
160158
return NULL;
161159
}
162160
st = get_module_state(mod);

0 commit comments

Comments
 (0)