Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add enum() example for named tuples #46754

Closed
calvin mannequin opened this issue Mar 28, 2008 · 5 comments
Closed

Add enum() example for named tuples #46754

calvin mannequin opened this issue Mar 28, 2008 · 5 comments
Assignees
Labels
docs Documentation in the Doc dir

Comments

@calvin
Copy link
Mannequin

calvin mannequin commented Mar 28, 2008

BPO 2502
Nosy @birkenfeld, @rhettinger, @amauryfa
Files
  • 0001-Add-enum-example-for-named-tuples.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/birkenfeld'
    closed_at = <Date 2008-03-28.12:58:44.696>
    created_at = <Date 2008-03-28.11:05:18.901>
    labels = ['docs']
    title = 'Add enum() example for named tuples'
    updated_at = <Date 2008-03-29.09:58:02.668>
    user = 'https://bugs.python.org/calvin'

    bugs.python.org fields:

    activity = <Date 2008-03-29.09:58:02.668>
    actor = 'rhettinger'
    assignee = 'georg.brandl'
    closed = True
    closed_date = <Date 2008-03-28.12:58:44.696>
    closer = 'georg.brandl'
    components = ['Documentation']
    creation = <Date 2008-03-28.11:05:18.901>
    creator = 'calvin'
    dependencies = []
    files = ['9881']
    hgrepos = []
    issue_num = 2502
    keywords = ['patch']
    message_count = 5.0
    messages = ['64627', '64629', '64635', '64636', '64689']
    nosy_count = 4.0
    nosy_names = ['georg.brandl', 'rhettinger', 'calvin', 'amaury.forgeotdarc']
    pr_nums = []
    priority = 'normal'
    resolution = 'rejected'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue2502'
    versions = ['Python 2.6']

    @calvin
    Copy link
    Mannequin Author

    calvin mannequin commented Mar 28, 2008

    Named tuples can also be used to emulate enum datatypes. The patch adds
    an example to the documentation.

    @calvin calvin mannequin assigned birkenfeld Mar 28, 2008
    @calvin calvin mannequin added the docs Documentation in the Doc dir label Mar 28, 2008
    @calvin
    Copy link
    Mannequin Author

    calvin mannequin commented Mar 28, 2008

    The motivation for this patch is that documenting a single function
    adding enum-like capabilities would hopefully eliminate the numerous
    "enum" recipies already out there, each handling things a little different.

    @birkenfeld
    Copy link
    Member

    birkenfeld commented Mar 28, 2008

    Fixed example (a * was missing) and committed as r62007. Thanks!

    @amauryfa
    Copy link
    Member

    amauryfa commented Mar 28, 2008

    Raymond, is this kind of recipes worth adding to the 'collections' module?

    Maybe with the following form:

    def enum(*valuenames):
         return namedtuple('Enum', valuenames)(*range(len(valuenames)))

    @rhettinger
    Copy link
    Contributor

    rhettinger commented Mar 29, 2008

    Thanks for asking. This should not go into the collections module.

    The concept makes more sense in statically compiled languages. In
    Python, we typically write something like "RED, ORANGE, YELLOW = range
    (3)" at the module level. That is faster and still allows prefixing
    using the module name (for example, re.MULTILINE).

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    docs Documentation in the Doc dir
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants