Skip to content

Change from constants to enums #5875

@melonmouse

Description

@melonmouse

Feature request

Example set of constants that would fit into an enum really well:

https://pillow.readthedocs.io/en/stable/_modules/PIL/Image.html#Image.transpose

That could be refactored to:

class TransposeType(enum.IntEnum):
    FLIP_LEFT_RIGHT = 0
    FLIP_TOP_BOTTOM = 1
    [etc]

FLIP_LEFT_RIGHT = TransposeType.FLIP_LEFT_RIGHT
FLIP_TOP_BOTTOM = TransposeType.FLIP_TOP_BOTTOM
[etc]

Advantages:

  • easier to check if a value is as expected (check type of enum value)

Disadvantages:

  • have to research if any existing usages can break

Smaller factors:

  • (some) refactoring required
  • (negligible) performance overhead

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions