Skip to content

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