1. stoneleaf
  2. aenum

Pull requests

#1 Open
Repository
otirosh
Branch
default
Repository
stoneleaf
Branch
default

Preserve eval(repr(x)) == x

Bitbucket cannot automatically merge this request.

The commits that make up this pull request have been removed.

Bitbucket cannot automatically merge this request due to conflicts.

Review the conflicts on the Overview tab. You can then either decline the request or merge it manually on your local system using the following commands:

hg update default
hg pull -r default https://bitbucket.org/otirosh/aenum
hg merge 9e983eaa91a3
hg commit -m 'Merged in otirosh/aenum (pull request #1)'
Author
  1. Oren Tirosh
Reviewers
Description

This modification makes Enum values preserve the same invariant as other Python value types: eval(repr(x)) == x. This is useful for, for example, when copy-and-pasting values of data structures at the interactive prompt, creating doctests, etc.

Color.red [value=1] -> Color.red (value=1)

The PEP8 violation (space between the enum name and value assertion) is intentional in order to make it look more like a parenthetical comment than a method call.

Downside: makes all enum values callable. This might be slightly surprising for users. If this is determined to be an issue, here are some possible alternatives:

Color.red .hasvalue(1)

Color['red', 1]

Color(red=1)

  • Learn about pull requests

Comments (0)