Skip to content

Fix Enum type definition #8624

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

Merged
merged 1 commit into from
Jul 16, 2025

Conversation

fliiiix
Copy link
Contributor

@fliiiix fliiiix commented Jun 23, 2025

Using the : syntax leads to non member attributes.

If an attribute is defined in the class body with a type annotation
but with no assigned value, a type checker should assume this is a non-member attribute

class Pet(Enum):
    genus: str  # Non-member attribute
    species: str  # Non-member attribute

    CAT = 1  # Member attribute
    DOG = 2  # Member attribute

https://typing.python.org/en/latest/spec/enums.html#defining-members

@github-actions github-actions bot added c++ codegen Involving generating code from schema python labels Jun 23, 2025
@fliiiix fliiiix force-pushed the bugfix/enum-type-definition branch from c47ca1d to 3335fbc Compare June 25, 2025 06:15
@fliiiix fliiiix force-pushed the bugfix/enum-type-definition branch from 3335fbc to a3bcf6e Compare July 8, 2025 11:34
Using the : syntax leads to non member attributes.

> If an attribute is defined in the class body with a type annotation
> but with no assigned value, a type checker should assume this is a non-member attribute

```
class Pet(Enum):
    genus: str  # Non-member attribute
    species: str  # Non-member attribute

    CAT = 1  # Member attribute
    DOG = 2  # Member attribute
```

https://typing.python.org/en/latest/spec/enums.html#defining-members
@fliiiix fliiiix force-pushed the bugfix/enum-type-definition branch from a3bcf6e to 6c65565 Compare July 16, 2025 15:18
@fliiiix
Copy link
Contributor Author

fliiiix commented Jul 16, 2025

@aardappel i think this is the last fix required to make python enums fully type check-able with mypy or similar

@aardappel aardappel merged commit 1047d7e into google:master Jul 16, 2025
51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ codegen Involving generating code from schema python
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants