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

Change from constants to enums #5875

Closed
melonmouse opened this issue Dec 7, 2021 · 4 comments · Fixed by #5954
Closed

Change from constants to enums #5875

melonmouse opened this issue Dec 7, 2021 · 4 comments · Fixed by #5954

Comments

@melonmouse
Copy link

melonmouse commented Dec 7, 2021

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
@kero-ly
Copy link

kero-ly commented Dec 8, 2021

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

@radarhere
Copy link
Member

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

@melonmouse
Copy link
Author

Awesome work radarhere, left a review there!

@radarhere radarhere changed the title Feature request: change from constants to enums Change from constants to enums Jan 18, 2022
@radarhere
Copy link
Member

radarhere commented Oct 25, 2022

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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants