Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-2059

Support for Python 3.4 enums

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 0.9
    • 0.17.0
    • Python - Compiler
    • None
    • Patch Available

    Description

      Currently enums are represented in Python by classes (see THRIFT-546) but those classes are not referenced by the actual values (which are simply i32s). This means that it's impossible to find out whether something is an enum or an i32 by inspection.

      e.g. I want to be able to look at the number 1 and realise it's an Operation.ADD or similar.

      I propose adding an option 'enum' to the generator to support Python 3.4 style enums (see enum34 package on pypi). Any I32 that should be an enum is automatically converted into an IntEnum derived object on deserialising, and constants are also constructed with the correct type. If one chooses to enable the option, it's almost backwards compatible with existing code due to IntEnum, except that the dicts _VALUES_FOR_NAME/_NAMES_FOR_VALUES have been removed (no longer necessary, and don't play nicely with the Enum class).

      Attachments

        Activity

          People

            kwojniak_box Kevin Wojniak
            wryun James Haggerty
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 3.5h
                3.5h