-
Notifications
You must be signed in to change notification settings - Fork 15.6k
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
Make generated python files compatible with Cython #11011
Conversation
Replace access to variables created in globals() by explicit access to the globals() array. This avoids static analysis of the code to error out on those unknown variables, and make the files cythonable.
Replace access to variables created in globals() by explicit access to the globals() array. This avoids static analysis of the code to error out on those unknown variables, and make the files cythonable. Fixes #10800 Closes #11011 FUTURE_COPYBARA_INTEGRATE_REVIEW=#11011 from vthib:10800-cython-compatibility 705da40 PiperOrigin-RevId: 493055381
@haberman Sorry, you referenced this PR last month. But it seems to have been closed by a bot. Do you have any plan to release this? I'm using flake8, and face a similar problem.
|
This got closed by a bot because it was submitted separately here: e3ea044. We use a tool that sometimes does this where it closes a PR and then submits the commit separately. On a manual check, I'm pretty sure this got into the 22.x branch (e3ea044), so it should be in the 22.0/22.1 release. Are you using that version? If you still see this issue in 22, please open a new issue so we can investigate it separately. |
@deannagarcia thank you for your reply. it works with v22 release!~ 😄 sorry it took so long to revert. i was unable to test it properly in my CI flow, mainly because it's not available in grpcio-tools v1.53.0 yet. i think i have to wait for it to be released here to properly list it in dependencies and CI tools.
but i generated the
thanks for your help. 🙇 |
This is a follow-up to protocolbuffers#11011 The generation is still not compatible with Cython when maps are used. For example, this protobuf file: ``` syntax = "proto3"; message Foo { map<string, string> bar = 1; } ``` Will generate: ``` ... _globals = globals() _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'a_pb2', _globals) if _descriptor._USE_C_DESCRIPTORS == False: DESCRIPTOR._options = None _FOO_BARENTRY._options = None _FOO_BARENTRY._serialized_options = b'8\001' _globals['_FOO']._serialized_start=11 _globals['_FOO']._serialized_end=88 _globals['_FOO_BARENTRY']._serialized_start=46 _globals['_FOO_BARENTRY']._serialized_end=88 ``` The `_FOO_BARENTRY` variable is not defined anywhere and confuses cython. We can see the `_globals` used below, it is simply missing for the first two lines using `_FOO_BARENTRY`.
Replace access to variables created in globals() by explicit access to the globals() array. This avoids static analysis of the code to error out on those unknown variables, and make the files cythonable.
Fixes #10800