Commit 8d18e5d
committed
fix(base): fix bugs found in the printline/trprint/qprint rewrite
Fixes discovered while packaging up old WIP work (commit 9dc38f9,
"Consistent operation of printline()...") for review. Three separate
bugs, all in that same unreleased WIP, none of it previously merged
or published:
1. trprint()/qprint() silently shifted `file` into the 2nd positional
argument slot (`def trprint(T, file=False, **kwargs)`), when the
original, published, external-user-facing signatures had `orient`/
`delim` there instead. `trprint(T, 'angvec')` or the library's own
documented `x.printline('angvec')` example put 'angvec' into `file`
instead of `orient`, crashing with
`AttributeError: 'str' object has no attribute 'write'`.
Fixed by restoring the full original explicit parameter order for
trprint/qprint (trprint2 was already fine here - its parameter
order happened to be unaffected).
2. trprint2() captured `label` as an explicit parameter but its body
never forwarded it to tr2str2() - `trprint2(T, label='T')` silently
dropped the label from the output.
3. All three (trprint/trprint2/qprint) stopped returning the compact
string entirely, only printing it - breaking any caller using the
deprecated-but-still-supported `file=None` -> return string instead
of printing usage, which several existing tests rely on
(test_transforms3d.py::test_print, test_transforms2d.py::test_print2).
While fixing (3): the `file=None` "give me a string instead" pattern
is a wart worth phasing out rather than perpetuating silently - each
of these now has a real *2str()/q2str() sibling that does that
directly. So `file=None` is kept working (still returns the string,
still doesn't print) but now consistently raises a DeprecationWarning
and says so explicitly in the docstring via `.. deprecated::`,
pointing at tr2str()/tr2str2()/q2str() as the replacement.
All three now follow one consistent shape: always build the string via
the *2str()/q2str() sibling, always return it, print only when
file is not None (file=False, the default, resolves to None passed to
print() so contextlib.redirect_stdout() sees the current sys.stdout at
call time rather than whatever was captured when the function was
defined - the actual bug this WIP originally set out to fix).
Verified: file=None still returns the correct string with a
DeprecationWarning and no printing; the default path both prints
(confirmed via contextlib.redirect_stdout) and returns the same
string; full test suite green (338 passed, 4 skipped);
black --check clean at 23.10.0.1 parent bb1f6f7 commit 8d18e5d
3 files changed
Lines changed: 51 additions & 19 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1152 | 1152 | | |
1153 | 1153 | | |
1154 | 1154 | | |
1155 | | - | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
1156 | 1161 | | |
1157 | 1162 | | |
1158 | 1163 | | |
| |||
1182 | 1187 | | |
1183 | 1188 | | |
1184 | 1189 | | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
| 1193 | + | |
1185 | 1194 | | |
1186 | 1195 | | |
1187 | 1196 | | |
| 1197 | + | |
1188 | 1198 | | |
1189 | 1199 | | |
1190 | 1200 | | |
1191 | 1201 | | |
1192 | 1202 | | |
1193 | | - | |
1194 | | - | |
1195 | | - | |
| 1203 | + | |
| 1204 | + | |
| 1205 | + | |
| 1206 | + | |
| 1207 | + | |
| 1208 | + | |
| 1209 | + | |
1196 | 1210 | | |
1197 | 1211 | | |
1198 | 1212 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
963 | 963 | | |
964 | 964 | | |
965 | 965 | | |
966 | | - | |
967 | 966 | | |
968 | 967 | | |
969 | 968 | | |
| |||
974 | 973 | | |
975 | 974 | | |
976 | 975 | | |
977 | | - | |
978 | | - | |
979 | 976 | | |
980 | 977 | | |
981 | 978 | | |
| |||
1101 | 1098 | | |
1102 | 1099 | | |
1103 | 1100 | | |
1104 | | - | |
1105 | | - | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
1106 | 1104 | | |
1107 | 1105 | | |
1108 | 1106 | | |
| 1107 | + | |
1109 | 1108 | | |
1110 | 1109 | | |
1111 | 1110 | | |
1112 | 1111 | | |
1113 | 1112 | | |
1114 | | - | |
1115 | | - | |
1116 | | - | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
1117 | 1120 | | |
1118 | 1121 | | |
1119 | 1122 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2785 | 2785 | | |
2786 | 2786 | | |
2787 | 2787 | | |
2788 | | - | |
2789 | 2788 | | |
2790 | 2789 | | |
2791 | 2790 | | |
| |||
2904 | 2903 | | |
2905 | 2904 | | |
2906 | 2905 | | |
2907 | | - | |
| 2906 | + | |
| 2907 | + | |
| 2908 | + | |
| 2909 | + | |
| 2910 | + | |
| 2911 | + | |
| 2912 | + | |
| 2913 | + | |
| 2914 | + | |
2908 | 2915 | | |
2909 | 2916 | | |
2910 | 2917 | | |
| |||
2962 | 2969 | | |
2963 | 2970 | | |
2964 | 2971 | | |
2965 | | - | |
2966 | | - | |
| 2972 | + | |
| 2973 | + | |
| 2974 | + | |
2967 | 2975 | | |
2968 | 2976 | | |
2969 | 2977 | | |
2970 | 2978 | | |
| 2979 | + | |
2971 | 2980 | | |
| 2981 | + | |
| 2982 | + | |
2972 | 2983 | | |
2973 | 2984 | | |
2974 | 2985 | | |
2975 | 2986 | | |
2976 | | - | |
2977 | | - | |
2978 | | - | |
| 2987 | + | |
| 2988 | + | |
| 2989 | + | |
| 2990 | + | |
| 2991 | + | |
| 2992 | + | |
| 2993 | + | |
2979 | 2994 | | |
2980 | 2995 | | |
2981 | 2996 | | |
| |||
0 commit comments