Behavior of auto in Enum and Flag.
Chris Angelico
rosuav at gmail.com
Mon Apr 3 01:38:20 EDT 2017
On Mon, Apr 3, 2017 at 2:49 PM, Oren Ben-Kiki <python-oren at ben-kiki.org> wrote:
> "If the exact value is unimportant you may use auto instances and an
> appropriate value will be chosen for you."
>
> Choosing a value that conflicts with BAZ in above cases doesn't seem
> "appropriate" for a value that is "unimportant".
>
> The docs also state "Care must be taken if you mix auto with other values."
> - fair enough. But:
>
> First, why require "care" if the code can take care of the issue for us?
>
> Second, the docs don't go into further detail about what exactly to avoid.
> In particular, the docs do not state that the automatic value will only
> take into account the previous values, and will ignore following values.
Sounds to me like the current behaviour is compliant with what the
docs say, and as such, I would be disinclined to change the code.
Perhaps a documentation clarification would suffice?
"""Care must be taken if you mix auto with other values. In
particular, using auto() prior to explicitly-set values may result in
conflicts."""
ChrisA
More information about the Python-list
mailing list