-
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
python: pylint no-name-in-module #10372
Comments
From a quick git history browse, the change was introduced in this commit of doom ab4585a |
I was hoping you would be able to use our Perhaps we could change the generated code to explicitly assign the top-level globals. The main thing we are trying to avoid is having the generated code be tightly coupled to the core runtime. |
We're making great use of the
If that's possible, that'd be awesome! |
I think this should have been fixed by: #11011 Please let me know if this did not fix it. |
Oh wait, I take it back. That PR did not explicitly assign globals, it just made references happen through |
What is the current recommendation for projects using pylint and protobuf? |
Seems like there is some progress for pyi files in pylint: |
Any more update on this one? |
Six months on, any updates on this issue? It looks like a resolution is blocked by the pylint issues linked above? |
Using the proto file given in the original bug report: syntax = "proto3";
package foo;
// Foo service
service Foo {
// Say Foo
rpc SayFoo(SayFooRequest) returns (SayFooResponse) {}
}
// Say Foo Request
message SayFooRequest {}
// Say Foo Response
message SayFooResponse {} The current codegen output is: # -*- coding: utf-8 -*-
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: protoc_explorer/other2.proto
"""Generated protocol buffer code."""
import google3
from google.protobuf import descriptor as _descriptor
from google.protobuf import descriptor_pool as _descriptor_pool
from google.protobuf import symbol_database as _symbol_database
from google.protobuf.internal import builder as _builder
# @@protoc_insertion_point(imports)
_sym_db = _symbol_database.Default()
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1cprotoc_explorer/other2.proto\x12\x03\x66oo\"\x0f\n\rSayFooRequest\"\x10\n\x0eSayFooResponse2:\n\x03\x46oo\x12\x33\n\x06SayFoo\x12\x12.foo.SayFooRequest\x1a\x13.foo.SayFooResponse\"\x00\x62\x06proto3')
_globals = globals()
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'google3.protoc_explorer.other2_pb2', _globals)
if _descriptor._USE_C_DESCRIPTORS == False:
DESCRIPTOR._loaded_options = None
_globals['_SAYFOOREQUEST']._serialized_start=37
_globals['_SAYFOOREQUEST']._serialized_end=52
_globals['_SAYFOORESPONSE']._serialized_start=54
_globals['_SAYFOORESPONSE']._serialized_end=70
_globals['_FOO']._serialized_start=72
_globals['_FOO']._serialized_end=130
# @@protoc_insertion_point(module_scope) It seems like it should address the issue if we just change this to: # -*- coding: utf-8 -*-
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: protoc_explorer/other2.proto
"""Generated protocol buffer code."""
import google3
from google.protobuf import descriptor as _descriptor
from google.protobuf import descriptor_pool as _descriptor_pool
from google.protobuf import symbol_database as _symbol_database
from google.protobuf.internal import builder as _builder
# @@protoc_insertion_point(imports)
_sym_db = _symbol_database.Default()
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1cprotoc_explorer/other2.proto\x12\x03\x66oo\"\x0f\n\rSayFooRequest\"\x10\n\x0eSayFooResponse2:\n\x03\x46oo\x12\x33\n\x06SayFoo\x12\x12.foo.SayFooRequest\x1a\x13.foo.SayFooResponse\"\x00\x62\x06proto3')
_globals = {}
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'google3.protoc_explorer.other2_pb2', _globals)
if _descriptor._USE_C_DESCRIPTORS == False:
DESCRIPTOR._loaded_options = None
_globals['_SAYFOOREQUEST']._serialized_start=37
_globals['_SAYFOOREQUEST']._serialized_end=52
_globals['_SAYFOORESPONSE']._serialized_start=54
_globals['_SAYFOORESPONSE']._serialized_end=70
_globals['_FOO']._serialized_start=72
_globals['_FOO']._serialized_end=130
# @@protoc_insertion_point(module_scope)
# Assign all top-level globals explicitly.
SayFooRequest = _globals['SayFooRequest']
SayFooResponse = _globals['SayFooResponse'] Does that sound accurate? @anandolee could you take a look? |
Any update on this? |
We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment. This issue is labeled |
The problem stayed the same until now.
@anandolee Do you have any updates on this problem? |
We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment. This issue is labeled |
Still an issue with
|
have you tried using --prefer-stubs when using pylint? Helped me. |
Helped me, too. Option added in pylint 3.2.1. |
Oh my god this fixed my hours of debugging. THANK YOU! |
Adding |
Same for me - it also created some issues with numpy, which led me to open this issue - sounds like |
We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment. This issue is labeled |
This issue should remain active |
Since v3.20.0 generated protobuf files trigger pylint
no-name-in-module
when importing the message types.Compiling
foo.proto
(see below) on two different protobuf versions obviously different results, however the old (3.19.x) can be pylinted successfully, but the new (3.20.x) result cannot be pylinted.Compilation command:
python3 -m grpc_tools.protoc -I . --python_out=. foo.proto
libprotoc 3.19.4 output
libprotoc 3.20.1 output
Test file (
test.py
)Running
pylint --disable=all --enable=no-name-in-module test.py
With 3.19.x generated code
With 3.20.x generated code
Clearly this is due to the abuse of
globals()
when using the builder to inject the descriptors into the module context.However, this is dynamically generated code, why does it have to be so clever (c.f.: obfuscated) that industry standard tooling can't ensure that your code is integrating with the library code properly?
The text was updated successfully, but these errors were encountered: