Skip to content

Commit 4bb9210

Browse files
committed
Set type names earlier in posixmodule.c
1 parent d301587 commit 4bb9210

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
@@ -8661,7 +8661,7 @@ static PyStructSequence_Field sched_param_fields[] = {
86618661
};
86628662

86638663
static PyStructSequence_Desc sched_param_desc = {
8664-
"sched_param", /* name */
8664+
MODNAME ".sched_param", /* name */
86658665
os_sched_param__doc__, /* doc */
86668666
sched_param_fields,
86678667
1
@@ -11055,7 +11055,7 @@ and elapsed.\n\
1105511055
See os.times for more information.");
1105611056

1105711057
static PyStructSequence_Desc times_result_desc = {
11058-
"times_result", /* name */
11058+
MODNAME ".times_result", /* name */
1105911059
times_result__doc__, /* doc */
1106011060
times_result_fields,
1106111061
5
@@ -18582,14 +18582,12 @@ posixmodule_exec(PyObject *m)
1858218582
}
1858318583

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

18592-
stat_result_desc.name = "os.stat_result"; /* see issue #19209 */
1859318591
stat_result_desc.fields[7].name = PyStructSequence_UnnamedField;
1859418592
stat_result_desc.fields[8].name = PyStructSequence_UnnamedField;
1859518593
stat_result_desc.fields[9].name = PyStructSequence_UnnamedField;
@@ -18600,14 +18598,12 @@ posixmodule_exec(PyObject *m)
1860018598
state->statresult_new_orig = ((PyTypeObject *)state->StatResultType)->tp_new;
1860118599
((PyTypeObject *)state->StatResultType)->tp_new = statresult_new;
1860218600

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

1860918606
#if defined(HAVE_SCHED_SETPARAM) || defined(HAVE_SCHED_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDPARAM)
18610-
sched_param_desc.name = MODNAME ".sched_param";
1861118607
state->SchedParamType = (PyObject *)PyStructSequence_NewType(&sched_param_desc);
1861218608
if (PyModule_AddObjectRef(m, "sched_param", state->SchedParamType) < 0) {
1861318609
return -1;
@@ -18639,7 +18635,6 @@ posixmodule_exec(PyObject *m)
1863918635
return -1;
1864018636
}
1864118637

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

0 commit comments

Comments
 (0)