thrift icon indicating copy to clipboard operation
thrift copied to clipboard

Fix python compiler generated all_structs with type_hints

Open fishy opened this issue 1 year ago • 3 comments

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 avatar Sep 17 '24 16:09 fishy

~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.

fishy avatar Sep 17 '24 16:09 fishy

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

SalomonSmeke avatar Sep 17 '24 17:09 SalomonSmeke

Working on adding more to this.

salomon-smekecohen avatar Dec 19 '24 17:12 salomon-smekecohen