Skip to content

Commit 4641925

Browse files
authored
Set type names earlier in posixmodule.c (#140168)
1 parent 7ac94fc commit 4641925

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

Lib/test/test_os/test_os.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,20 @@ def test_getcwdb(self):
164164
self.assertIsInstance(cwd, bytes)
165165
self.assertEqual(os.fsdecode(cwd), os.getcwd())
166166

167+
def test_type_fqdn(self):
168+
def fqdn(obj):
169+
return (obj.__module__, obj.__qualname__)
170+
171+
native = os.name
172+
self.assertEqual(fqdn(os.stat_result), ("os", "stat_result"))
173+
self.assertEqual(fqdn(os.times_result), (native, "times_result"))
174+
if hasattr(os, "statvfs_result"):
175+
self.assertEqual(fqdn(os.statvfs_result), ("os", "statvfs_result"))
176+
if hasattr(os, "sched_param"):
177+
self.assertEqual(fqdn(os.sched_param), (native, "sched_param"))
178+
if hasattr(os, "waitid_result"):
179+
self.assertEqual(fqdn(os.waitid_result), (native, "waitid_result"))
180+
167181

168182
# Tests creating TESTFN
169183
class FileTests(unittest.TestCase):

Modules/posixmodule.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2471,7 +2471,7 @@ static PyStructSequence_Field stat_result_fields[] = {
24712471
#endif
24722472

24732473
static PyStructSequence_Desc stat_result_desc = {
2474-
"stat_result", /* name */
2474+
"os.stat_result", /* name; see issue gh-63408 */
24752475
stat_result__doc__, /* doc */
24762476
stat_result_fields,
24772477
10
@@ -2501,7 +2501,7 @@ static PyStructSequence_Field statvfs_result_fields[] = {
25012501
};
25022502

25032503
static PyStructSequence_Desc statvfs_result_desc = {
2504-
"statvfs_result", /* name */
2504+
"os.statvfs_result", /* name; see issue gh-63408 */
25052505
statvfs_result__doc__, /* doc */
25062506
statvfs_result_fields,
25072507
10
@@ -2526,7 +2526,7 @@ static PyStructSequence_Field waitid_result_fields[] = {
25262526
};
25272527

25282528
static PyStructSequence_Desc waitid_result_desc = {
2529-
"waitid_result", /* name */
2529+
MODNAME ".waitid_result", /* name */
25302530
waitid_result__doc__, /* doc */
25312531
waitid_result_fields,
25322532
5
@@ -8663,7 +8663,7 @@ static PyStructSequence_Field sched_param_fields[] = {
86638663
};
86648664

86658665
static PyStructSequence_Desc sched_param_desc = {
8666-
"sched_param", /* name */
8666+
MODNAME ".sched_param", /* name */
86678667
os_sched_param__doc__, /* doc */
86688668
sched_param_fields,
86698669
1
@@ -11057,7 +11057,7 @@ and elapsed.\n\
1105711057
See os.times for more information.");
1105811058

1105911059
static PyStructSequence_Desc times_result_desc = {
11060-
"times_result", /* name */
11060+
MODNAME ".times_result", /* name */
1106111061
times_result__doc__, /* doc */
1106211062
times_result_fields,
1106311063
5
@@ -18584,14 +18584,12 @@ posixmodule_exec(PyObject *m)
1858418584
}
1858518585

1858618586
#if defined(HAVE_WAITID)
18587-
waitid_result_desc.name = MODNAME ".waitid_result";
1858818587
state->WaitidResultType = (PyObject *)PyStructSequence_NewType(&waitid_result_desc);
1858918588
if (PyModule_AddObjectRef(m, "waitid_result", state->WaitidResultType) < 0) {
1859018589
return -1;
1859118590
}
1859218591
#endif
1859318592

18594-
stat_result_desc.name = "os.stat_result"; /* see issue #19209 */
1859518593
stat_result_desc.fields[7].name = PyStructSequence_UnnamedField;
1859618594
stat_result_desc.fields[8].name = PyStructSequence_UnnamedField;
1859718595
stat_result_desc.fields[9].name = PyStructSequence_UnnamedField;
@@ -18602,14 +18600,12 @@ posixmodule_exec(PyObject *m)
1860218600
state->statresult_new_orig = ((PyTypeObject *)state->StatResultType)->tp_new;
1860318601
((PyTypeObject *)state->StatResultType)->tp_new = statresult_new;
1860418602

18605-
statvfs_result_desc.name = "os.statvfs_result"; /* see issue #19209 */
1860618603
state->StatVFSResultType = (PyObject *)PyStructSequence_NewType(&statvfs_result_desc);
1860718604
if (PyModule_AddObjectRef(m, "statvfs_result", state->StatVFSResultType) < 0) {
1860818605
return -1;
1860918606
}
1861018607

1861118608
#if defined(HAVE_SCHED_SETPARAM) || defined(HAVE_SCHED_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDPARAM)
18612-
sched_param_desc.name = MODNAME ".sched_param";
1861318609
state->SchedParamType = (PyObject *)PyStructSequence_NewType(&sched_param_desc);
1861418610
if (PyModule_AddObjectRef(m, "sched_param", state->SchedParamType) < 0) {
1861518611
return -1;
@@ -18641,7 +18637,6 @@ posixmodule_exec(PyObject *m)
1864118637
return -1;
1864218638
}
1864318639

18644-
times_result_desc.name = MODNAME ".times_result";
1864518640
state->TimesResultType = (PyObject *)PyStructSequence_NewType(&times_result_desc);
1864618641
if (PyModule_AddObjectRef(m, "times_result", state->TimesResultType) < 0) {
1864718642
return -1;

0 commit comments

Comments
 (0)