New submission from Ethan Furman <et...@stoneleaf.us>:
In the Python 3.10 Doc/library/enum.rst file was the following: .. class:: FlagBoundary *FlagBoundary* controls how out-of-range values are handled in *Flag* and its subclasses. .. attribute:: STRICT Out-of-range values cause a :exc:`ValueError` to be raised. This is the default for :class:`Flag`:: >>> from enum import STRICT >>> class StrictFlag(Flag, boundary=STRICT): ... RED = auto() ... GREEN = auto() ... BLUE = auto() >>> StrictFlag(2**2 + 2**4) Traceback (most recent call last): ... ValueError: StrictFlag: invalid value: 20 given 0b0 10100 allowed 0b0 00111 .. attribute:: CONFORM Out-of-range values have invalid values removed, leaving a valid *Flag* value:: >>> from enum import CONFORM >>> class ConformFlag(Flag, boundary=CONFORM): ... RED = auto() ... GREEN = auto() ... BLUE = auto() >>> ConformFlag(2**2 + 2**4) ConformFlag.BLUE .. attribute:: EJECT Out-of-range values lose their *Flag* membership and revert to :class:`int`. This is the default for :class:`IntFlag`:: >>> from enum import EJECT >>> class EjectFlag(Flag, boundary=EJECT): ... RED = auto() ... GREEN = auto() ... BLUE = auto() >>> EjectFlag(2**2 + 2**4) 20 .. attribute:: KEEP Out-of-range values are kept, and the *Flag* membership is kept. This is used for some stdlib flags: >>> from enum import KEEP >>> class KeepFlag(Flag, boundary=KEEP): ... RED = auto() ... GREEN = auto() ... BLUE = auto() >>> KeepFlag(2**2 + 2**4) KeepFlag.BLUE|0x10 All four tests are relying on a previous `from enum import Flag`, but only the three tests pass -- the fourth raises: Traceback (most recent call last): File "/home/runner/work/cpython/cpython/Lib/doctest.py", line 1337, in __run exec(compile(example.source, filename, "single", File "<doctest default[1]>", line 1, in <module> class KeepFlag(Flag, boundary=KEEP): NameError: name 'Flag' is not defined ---------- components: Library (Lib) messages: 389903 nosy: ethan.furman priority: normal severity: normal stage: test needed status: open title: doctest forgets previous imports type: behavior versions: Python 3.10 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue43681> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com