镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Change from constants to enums #5875

Closed

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

Activity

  1. kero-ly commented on Dec 8, 2021

    @kero-ly

    I think it's designed for casting int value from python to cpp conveniently, and validate it cpp :D

  2. radarhere commented on Jan 11, 2022

    @radarhere
    Member

    I've created #5954 to resolve this. See what you think.

  3. melonmouse commented on Jan 11, 2022

    @melonmouse
    Author

    Awesome work radarhere, left a review there!

  4. changed the title [-]Feature request: change from constants to enums[/-] [+]Change from constants to enums[/+] on Jan 18, 2022
  5. radarhere commented on Oct 25, 2022

    @radarhere
    Member

    Be aware that #6684 has been proposed, which would revert the changes for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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