Commit 2587813
committed
Fixed crash in Python 3.15.0a6
The crash was caused by changes in the argparse internal API in Python 3.15, specifically in how it handles colorization and formatter initialization.
Changes Made:
1. Cmd2HelpFormatter._set_color: Added an override for the _set_color method to handle the new file keyword argument introduced in Python 3.15. It uses a try-except block to fall back to the older signature if the underlying RichHelpFormatter (from rich-argparse) does not yet support the new keyword argument.
2. Cmd2ArgumentParser._get_formatter: Updated the _get_formatter method to accept **kwargs and pass them to the superclass. This is necessary because Python 3.15's argparse now passes a file argument to this method in several places (e.g., print_usage).
3. TextGroup.__init__: Updated the type hint for the formatter_creator parameter from Callable[[], Cmd2HelpFormatter] to Callable[..., Cmd2HelpFormatter] to remain consistent with the updated _get_formatter signature.1 parent 42d2271 commit 2587813
1 file changed
+15
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1030 | 1030 | | |
1031 | 1031 | | |
1032 | 1032 | | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
1033 | 1045 | | |
1034 | 1046 | | |
1035 | 1047 | | |
| |||
1134 | 1146 | | |
1135 | 1147 | | |
1136 | 1148 | | |
1137 | | - | |
| 1149 | + | |
1138 | 1150 | | |
1139 | 1151 | | |
1140 | 1152 | | |
| |||
1258 | 1270 | | |
1259 | 1271 | | |
1260 | 1272 | | |
1261 | | - | |
| 1273 | + | |
1262 | 1274 | | |
1263 | | - | |
| 1275 | + | |
1264 | 1276 | | |
1265 | 1277 | | |
1266 | 1278 | | |
| |||
0 commit comments