Commit 89f962a
lifetime: reject negative, non-numeric, and bool values at the setter
lifetime.setter stored whatever it received and trusted the call site
to pass a non-negative number. A negative value, a non-numeric string,
or a bool (bool is a subclass of int, so it slipped past the int check)
would be remembered as the expiration window and only blow up later
inside _try_break_expired_lock, or quietly compare against st_mtime
and behave in surprising ways.
Validate at the boundary the same way timeout.setter validates (it
calls float(value) and lets ValueError propagate). The new behavior:
- None is accepted (disables expiration, the documented contract).
- int and float that are >= 0 are accepted.
- bool is rejected with TypeError so True/False cannot be misread as
a 1-second or 0-second lifetime.
- non-numeric objects raise TypeError with the offending type name
instead of a confusing downstream TypeError in arithmetic.
- negative numbers raise ValueError with the offending value
inlined, matching the docstring promise that lifetime is a
maximum time in seconds.1 parent c76dee6 commit 89f962a
2 files changed
Lines changed: 38 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
346 | 346 | | |
347 | 347 | | |
348 | 348 | | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
349 | 352 | | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
350 | 360 | | |
351 | 361 | | |
352 | 362 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
76 | 104 | | |
77 | 105 | | |
78 | 106 | | |
| |||
0 commit comments