python / cpython

The Python programming language
https://www.python.org
Other
63.61k stars 30.47k forks source link

Add a "warning" option to enum.FlagBoundary #99999

Open aragilar opened 1 year ago

aragilar commented 1 year ago

Feature or enhancement

The new enum.FlagBoundary system seems quite nice, but there does not appear to be an option to accept a value (a.k.a KEEP) but warn when out of range (STRICT throws an error, and would require a second class to wrap the value).

Pitch

I see two possible options:

  1. Add a new flag (e.g. WARN or WARN_KEEP) which warns when the value is out of range
  2. Modify KEEP such that a warning is displayed when the value is out of range

(1) seems like the better option from a backwards-compatibility perspective, but (2) seems like the better option from a usability and maintenance perspective (as missing values are easier to spot).

Previous discussion

None

ethanfurman commented 1 year ago

This is an interesting idea. Still thinking on it.