Commit 2306799
committed
Fix 13 latent bugs found by a full-source audit
Metaclass (parser.py):
- Copy a shared Argument() instance before inferring type/nargs/choices:
one instance bound to several fields/classes was mutated in place, so
`b: str = arg` silently required the int type inferred for `a: int`.
- Reject arguments that would shadow methods/properties (parse_args,
print_help, user-defined helpers): the metaclass used to replace them
with `...` placeholders, silently destroying the parser API.
- Reject a bare `serve: Serve` annotation (no instance): it silently
became a required CLI argument with type=<Parser class>.
- Inherit unannotated arguments, groups, and subparsers: previously a
subclass lost every `tags = Argument(...)`, `db = DB()` or
`serve = Serve()` declared on its base class.
- Preserve inherited plain defaults: `name: str = "x"` used to become
a *required* argument in every subclass because the processed class
attribute had been replaced with an Ellipsis placeholder.
- Wrap each element of Secret(nargs=...) lists in SecretString; only
scalar secrets were masked, so repr(list) leaked the values.
- Remove dead code in the Optional-unwrap branch.
Config parsers (defaults.py, actions.py):
- Make strict=False consistent: malformed INI/TOML files are now
skipped like JSON ones instead of raising; strict=True still raises.
- Alias INIDefaultsParser.BOOL_TRUE_VALUES to types.TEXT_TRUE_VALUES
(the two identical sets could drift apart).
- ConfigAction caches results via a None sentinel instead of
truthiness, so an empty config is parsed once.
Factory (factory.py):
- EnumArgument(lowercase=True) now uses an explicit name map instead
of str.upper() round-trips, fixing enums with non-uppercase member
names; enum aliases (e.g. LogLevelEnum.WARN) remain accepted.
Docs (pitfalls.md):
- Unselected subcommand attributes raise AttributeError; the page
claimed they "retain their default values".
- Document that Group/subparser attributes are class-level singletons
shared by all instances of a Parser class.
tests/test_audit_fixes.py covers every fix; 21 of its 38 tests fail
against the pre-fix code.1 parent b4d7f01 commit 2306799
6 files changed
Lines changed: 779 additions & 43 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
73 | | - | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
74 | 77 | | |
75 | 78 | | |
76 | 79 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
166 | 167 | | |
167 | 168 | | |
168 | 169 | | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
182 | 175 | | |
183 | 176 | | |
184 | 177 | | |
185 | 178 | | |
186 | 179 | | |
187 | 180 | | |
188 | 181 | | |
189 | | - | |
190 | | - | |
191 | | - | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
192 | 195 | | |
193 | 196 | | |
194 | 197 | | |
| |||
275 | 278 | | |
276 | 279 | | |
277 | 280 | | |
278 | | - | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
279 | 285 | | |
280 | 286 | | |
281 | 287 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
537 | 537 | | |
538 | 538 | | |
539 | 539 | | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
540 | 547 | | |
| 548 | + | |
541 | 549 | | |
542 | 550 | | |
| 551 | + | |
543 | 552 | | |
544 | 553 | | |
545 | 554 | | |
546 | 555 | | |
547 | 556 | | |
548 | 557 | | |
549 | 558 | | |
550 | | - | |
551 | | - | |
552 | | - | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
553 | 563 | | |
554 | 564 | | |
555 | 565 | | |
556 | 566 | | |
557 | | - | |
| 567 | + | |
558 | 568 | | |
559 | | - | |
560 | | - | |
| 569 | + | |
561 | 570 | | |
562 | 571 | | |
563 | 572 | | |
| |||
574 | 583 | | |
575 | 584 | | |
576 | 585 | | |
577 | | - | |
578 | | - | |
579 | | - | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
580 | 592 | | |
581 | 593 | | |
582 | 594 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
91 | 91 | | |
92 | 92 | | |
93 | 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 | + | |
94 | 147 | | |
95 | 148 | | |
96 | 149 | | |
| |||
113 | 166 | | |
114 | 167 | | |
115 | 168 | | |
116 | | - | |
117 | | - | |
118 | | - | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
119 | 194 | | |
120 | 195 | | |
121 | 196 | | |
| |||
126 | 201 | | |
127 | 202 | | |
128 | 203 | | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
129 | 222 | | |
130 | 223 | | |
131 | 224 | | |
132 | 225 | | |
133 | 226 | | |
134 | 227 | | |
135 | 228 | | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
136 | 261 | | |
137 | 262 | | |
138 | 263 | | |
| |||
292 | 417 | | |
293 | 418 | | |
294 | 419 | | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
295 | 425 | | |
296 | 426 | | |
297 | 427 | | |
298 | 428 | | |
299 | | - | |
300 | | - | |
301 | 429 | | |
302 | 430 | | |
303 | 431 | | |
| |||
339 | 467 | | |
340 | 468 | | |
341 | 469 | | |
342 | | - | |
| 470 | + | |
343 | 471 | | |
344 | | - | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
345 | 478 | | |
346 | 479 | | |
347 | 480 | | |
| |||
357 | 490 | | |
358 | 491 | | |
359 | 492 | | |
360 | | - | |
| 493 | + | |
361 | 494 | | |
362 | 495 | | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
363 | 503 | | |
364 | | - | |
| 504 | + | |
365 | 505 | | |
366 | | - | |
| 506 | + | |
367 | 507 | | |
368 | | - | |
| 508 | + | |
369 | 509 | | |
370 | 510 | | |
371 | 511 | | |
| |||
909 | 1049 | | |
910 | 1050 | | |
911 | 1051 | | |
912 | | - | |
913 | | - | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
914 | 1062 | | |
915 | 1063 | | |
916 | 1064 | | |
| |||
0 commit comments