Skip to content

When parsing enums derived from enum.Enum, non-canonical values are ignored #223

@bindreams

Description

@bindreams

My package does not use pybind11 hacky enums, but instead derives enums from enum.Enum using a popular helper macro.

However, in that case the generated stub does not contain some values, the ones that are considered non-canonical (as defined in this comment). These are zero values (maybe just in enum.Flag) and repeated/alias values.

I haven't looked at the implementation, but the issue is probably related to this: python/cpython#109633. If I'm correct, the issue can probable be fixed by iterating over the __members__ of the enum class.

Example of what I mean:

>>> list(iter(InputMode))
[<InputMode.UNICODE: 1>,
 <InputMode.GS1: 2>,
 <InputMode.ESCAPE: 8>,
 <InputMode.GS1PARENS: 16>,
 <InputMode.GS1NOCHECK: 32>,
 <InputMode.HEIGHTPERROW: 64>,
 <InputMode.FAST: 128>,
 <InputMode.EXTRA_ESCAPE: 256>]

>>> InputMode.__members__
mappingproxy({'DATA': <InputMode.DATA: 0>,
              'UNICODE': <InputMode.UNICODE: 1>,
              'GS1': <InputMode.GS1: 2>,
              'ESCAPE': <InputMode.ESCAPE: 8>,
              'GS1PARENS': <InputMode.GS1PARENS: 16>,
              'GS1NOCHECK': <InputMode.GS1NOCHECK: 32>,
              'HEIGHTPERROW': <InputMode.HEIGHTPERROW: 64>,
              'FAST': <InputMode.FAST: 128>,
              'EXTRA_ESCAPE': <InputMode.EXTRA_ESCAPE: 256>})

As you can see, with iter(), the DATA value is missing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions