Skip to content

Enum now accepts String literals and final ... #8664

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

Conversation

vincent-prz
Copy link
Contributor

This aims to solve #8219

This PR is still a draft, but am I going in the right direction ? I am doing lot of if refinements from line 150, in order to be compliant with mypy linting, maybe there is a less clunky way to achieve the same result ? Also, should the following cases typecheck ?

class A:
    x: Literal['x y'] = 'x y'

Coordinates = Enum('Coordinates', A.x)
def f() -> Literal['x y']
    return 'x y'

Coordinates = Enum('Coordinates', f())

Moreover, I had to add [builtins fixtures/tuple.pyi] in my tests, they would otherwise crash, but I am not sure to understand why.

values as 2nd arg. This aims to solve python#8219
@97littleleaf11
Copy link
Collaborator

cc @sobolevn

Copy link
Collaborator

@97littleleaf11 97littleleaf11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sobolevn Do you have any suggestions on this PR?

Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I've missed it! Thanks for the ping 🙂

from typing_extensions import Final

x: Final['str'] = 'ANT BEE CAT DOG'
Animal = Enum('Animal', x)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also check that Animal.ANT, Animal.BEE, etc are available in both test cases.

@97littleleaf11
Copy link
Collaborator

cc @sobolevn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants