Commit 50a2e22
committed
feat(os): custom repr for os.stat_result showing time fields by name
os.stat_result has three unnamed integer time slots (7-9) whose values are
mirrored by the named float fields st_atime/st_mtime/st_ctime (statresult_new
fills the latter from the former). The generic struct sequence repr shows
those unnamed slots as <unnamed@7..9>, which is uninformative.
Add statresult_repr showing the named fields (st_mode..st_size and the float
st_atime/st_mtime/st_ctime) by name, matching the attributes. Install it
through the type dict via PyObject_SetAttrString so repr() and st.__repr__()
resolve to the same function; a raw tp_repr assignment would leave the
__repr__ wrapper readied by PyStructSequence_NewType pointing at the generic
repr. Other struct sequences keep the generic <unnamed@N>.1 parent 227e089 commit 50a2e22
3 files changed
Lines changed: 144 additions & 32 deletions
File tree
- Lib/test
- Misc/NEWS.d/next/Core_and_Builtins
- Modules
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
79 | 55 | | |
80 | 56 | | |
81 | 57 | | |
| |||
108 | 84 | | |
109 | 85 | | |
110 | 86 | | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
111 | 150 | | |
112 | 151 | | |
113 | 152 | | |
| |||
Lines changed: 5 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2572 | 2572 | | |
2573 | 2573 | | |
2574 | 2574 | | |
| 2575 | + | |
| 2576 | + | |
2575 | 2577 | | |
2576 | 2578 | | |
2577 | 2579 | | |
| |||
2581 | 2583 | | |
2582 | 2584 | | |
2583 | 2585 | | |
| 2586 | + | |
| 2587 | + | |
| 2588 | + | |
| 2589 | + | |
| 2590 | + | |
| 2591 | + | |
| 2592 | + | |
| 2593 | + | |
| 2594 | + | |
| 2595 | + | |
| 2596 | + | |
| 2597 | + | |
| 2598 | + | |
| 2599 | + | |
| 2600 | + | |
| 2601 | + | |
| 2602 | + | |
| 2603 | + | |
| 2604 | + | |
| 2605 | + | |
| 2606 | + | |
| 2607 | + | |
| 2608 | + | |
| 2609 | + | |
| 2610 | + | |
| 2611 | + | |
| 2612 | + | |
| 2613 | + | |
| 2614 | + | |
| 2615 | + | |
| 2616 | + | |
| 2617 | + | |
| 2618 | + | |
| 2619 | + | |
| 2620 | + | |
| 2621 | + | |
| 2622 | + | |
| 2623 | + | |
| 2624 | + | |
| 2625 | + | |
| 2626 | + | |
| 2627 | + | |
| 2628 | + | |
| 2629 | + | |
| 2630 | + | |
| 2631 | + | |
| 2632 | + | |
| 2633 | + | |
| 2634 | + | |
| 2635 | + | |
| 2636 | + | |
| 2637 | + | |
| 2638 | + | |
| 2639 | + | |
| 2640 | + | |
| 2641 | + | |
| 2642 | + | |
2584 | 2643 | | |
2585 | 2644 | | |
2586 | 2645 | | |
| |||
18860 | 18919 | | |
18861 | 18920 | | |
18862 | 18921 | | |
| 18922 | + | |
| 18923 | + | |
| 18924 | + | |
| 18925 | + | |
| 18926 | + | |
| 18927 | + | |
| 18928 | + | |
| 18929 | + | |
| 18930 | + | |
| 18931 | + | |
| 18932 | + | |
| 18933 | + | |
| 18934 | + | |
| 18935 | + | |
18863 | 18936 | | |
18864 | 18937 | | |
18865 | 18938 | | |
| |||
0 commit comments