Behavior of auto in Enum and Flag.

Oren Ben-Kiki python-oren at ben-kiki.org
Mon Apr 3 02:10:25 EDT 2017


While "the current behaviour is compliant with what the docs say" is true,
saying "as such, I would be disinclined to change the code" misses the
point.

The current documentation allows for multiple behaviors. The current
implementation has an chosen to add an arbitrary undocumented restriction
on the behavior, which has a usability issue. Even worse, for no clear
reason, the current implementation forces _all_ implementations to suffer
from the same usability issue.

The proposed behavior is _also_ compliant with the current documentation,
and does not suffer from this usability issue. The proposed implementation
is compatible with existing code bases, and allows for "any" other
implementation to avoid this issue.

That is, I think that instead of enshrining the current implementation's
undocumented and arbitrary restriction, by explicitly adding it to the
documentation, we should instead remove this arbitrary restriction from the
implementation, and only modify the documentation to clarify this
restriction is gone.

Oren.

On Mon, Apr 3, 2017 at 8:38 AM, Chris Angelico <rosuav at gmail.com> wrote:

> 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
> --
> https://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list