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

Basic example not working #53

Open
danslinger opened this issue Jul 25, 2022 · 4 comments
Open

Basic example not working #53

danslinger opened this issue Jul 25, 2022 · 4 comments

Comments

@danslinger
Copy link

I am trying to get the basic example from the README to work. I created a fresh virtual environment using Python 3.10. Installed pylint, pylint-protobuf and protobuf. The output of my pip freeze is here:

dill==0.3.5.1
isort==5.10.1
lazy-object-proxy==1.7.1
mccabe==0.7.0
platformdirs==2.5.2
protobuf==4.21.2
pylint==2.14.5
pylint-protobuf==0.20.2
tomli==2.0.1
tomlkit==0.11.1
wrapt==1.14.1

I created the person.proto file, ran protoc python_out=. person.proto and see my generated person_pb2.py file in my workspace. I created a readme.py file slightly different from the example:

from person_pb2 import Person
p = Person()
p.name = "test"

Then I run the command pylint --load-plugins=pylint_protobuf readme.py and get the following output:

************* Module readme
readme.py:1:0: E0611: No name 'Person' in module 'person_pb2' (no-name-in-module)

Since its the basic example it feels like a "me" problem, but I'm not sure where I'm running astray?

@nelfin
Copy link
Owner

nelfin commented Jul 26, 2022

Hi @danslinger, thanks for the report. It could very well be an integration issue on my end: if I remember correctly at the time of the last release (of pylint-protobuf) astroid/pylint didn't yet support Python 3.10 so I was unable to check this. I'll update my test environments and try to reproduce the issue you're seeing.

@danslinger
Copy link
Author

Thanks for checking @nelfin . I neglected to mention I also did try this with a Python 3.8 virtual environment, and even stepped back a few versions of pylint (2.9 I think I tried).

@nelfin
Copy link
Owner

nelfin commented Jul 27, 2022

I wasn't able to reproduce this so there must be something extra that's different between our environments. It seems like your pip freeze output is missing astroid (I assume that's just a copy-paste error since pylint wouldn't work otherwise). Could you post the python.proto file and the generated person_pb2.py as well? Plus the output of protoc --version?

@danslinger
Copy link
Author

Yeah, the missing astroid was a copy/paste error. The version is astroid==2.11.7

person.proto

syntax = "proto3";

message Person {
    string name = 1;
}

person_pb2.py

# Generated by the protocol buffer compiler.  DO NOT EDIT!
# source: person.proto
"""Generated protocol buffer code."""
from google.protobuf.internal import builder as _builder
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
# @@protoc_insertion_point(imports)

_sym_db = _symbol_database.Default()




DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0cperson.proto\"\x16\n\x06Person\x12\x0c\n\x04name\x18\x01 \x01(\tb\x06proto3')

_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals())
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'person_pb2', globals())
if _descriptor._USE_C_DESCRIPTORS == False:

  DESCRIPTOR._options = None
  _PERSON._serialized_start=16
  _PERSON._serialized_end=38
# @@protoc_insertion_point(module_scope)

protoc --version

libprotoc 3.21.2

readme.py

""" A test module"""
from person_pb2 import Person

p = Person()
p.name = "Some Name"

pylint --load-plugins=pylint_protobuf readme.py

************* Module readme
readme.py:2:0: E0611: No name 'Person' in module 'person_pb2' (no-name-in-module)

------------------------------------------------------------------
Your code has been rated at 0.00/10 (previous run: 0.00/10, +0.00)

Full pip freeze output

astroid==2.11.7
dill==0.3.5.1
isort==5.10.1
lazy-object-proxy==1.7.1
mccabe==0.7.0
platformdirs==2.5.2
protobuf==4.21.2
pylint==2.14.5
pylint-protobuf==0.20.2
tomli==2.0.1
tomlkit==0.11.1
wrapt==1.14.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants