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

Fix python compiler generated all_structs with type_hints #3040

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fishy
Copy link
Member

@fishy fishy commented Sep 17, 2024

Currently with type_hints enabled, we do not explicitly declare the type of generated all_structs. It's meant to be a list of different types, but that will cause problems, as the generated code is usually like this:

all_structs = []
...
all_structs.append(Type1)
...
all_structs.append(Type2)
...

The first append infers the type of all_struct to be list[Type1], so mypy would start complaining from the 2nd append as the type is unexpected.

Explicitly declare all_struct to be list[typing.Any] instead, which fixes the issue.

@fishy
Copy link
Member Author

fishy commented Sep 17, 2024

NOTE: this fixes a bug in the new feature added to the 0.21.0 release, so it should ideally be part of the 0.21.0 release. changing this PR to target master branch (next release) instead.

@SalomonSmeke
Copy link

Thank You! One can skip type checking the import or get around this with implicit Any but its much nicer to have this declared :)

@fishy fishy changed the base branch from 0.21.0 to master September 17, 2024 17:44
Currently with type_hints enabled, we do not explicitly declare the type
of generated all_structs. It's meant to be a list of different types,
but that will cause problems, as the generated code is usually like
this:

    all_structs = []
    ...
    all_structs.append(Type1)
    ...
    all_structs.append(Type2)
    ...

The first append infers the type of all_struct to be list[Type1], so
mypyc would start complaining from the 2nd append as the type is
unexpected.

Explicitly declare all_struct to be list[typing.Any] instead, which
fixes the issue.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants