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

Module 'google.protobuf.any_pb2' has no 'Any' member #6281

Open
PhilippSelenium opened this issue Apr 12, 2022 · 14 comments
Open

Module 'google.protobuf.any_pb2' has no 'Any' member #6281

PhilippSelenium opened this issue Apr 12, 2022 · 14 comments
Labels
Help wanted 🙏 Outside help would be appreciated, good for new contributors Lib specific 💅 This affect the code from a particular library Needs astroid Brain 🧠 Needs a brain tip in astroid (then an astroid upgrade) Needs PR This issue is accepted, sufficiently specified and now needs an implementation

Comments

@PhilippSelenium
Copy link

PhilippSelenium commented Apr 12, 2022

Bug description

When running pylint on the following code:

from google.protobuf import any_pb2

isinstance("foo", any_pb2.Any)

Throws a linter warning since protobuf==3.20.0 (It still worked fine with 3.19.4)

Executing the code directly in python yields no error:

from google.protobuf import any_pb2
isinstance("foo", any_pb2.Any)
isinstance(any_pb2.Any(), any_pb2.Any)

Configuration

No response

Command used

pylint test.py

Pylint output

************* Module test
test.py:5:18: E1101: Module 'google.protobuf.any_pb2' has no 'Any' member (no-member)

Expected behavior

No warning.

Pylint version

pylint 2.12.1
astroid 2.9.0
Python 3.8.10 (default, Mar 15 2022, 12:22:08) 
[GCC 9.4.0]

OS / Environment

Ubuntu 20.04

Additional dependencies

protobuf==3.19.4
protobuf==3.20.0

@PhilippSelenium PhilippSelenium added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Apr 12, 2022
@mbmccoy
Copy link

mbmccoy commented May 7, 2022

I'm having a similar problem. It's related to this issue: protocolbuffers/protobuf#9730

The issue seems to stem from the fact that 3.20.0 protoc does in fact not directly define the classes that are expected, just a bunch of private variables. The classes are generated at import through python reflection.

However, there are correctly typed stub .pyi files that are generated. For some reason, it seems that pylint (and perhaps mypy) are ignoring generated pyi files.

I'll see if I can get a complete example and post a new issue in the next couple days.

(As an aside, the generated python protobuf code reads as something absolutely insane to python programmers.)

@Pierre-Sassoulas Pierre-Sassoulas added the Lib specific 💅 This affect the code from a particular library label May 13, 2022
@Pierre-Sassoulas Pierre-Sassoulas added Needs astroid Brain 🧠 Needs a brain tip in astroid (then an astroid upgrade) Needs investigation 🔬 A bug or crash where it's not immediately obvious what is happenning and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Jun 23, 2022
@belm0
Copy link
Contributor

belm0 commented Mar 17, 2023

This is pretty bad. A workaround like disabling no-name-in-module globally on my project is not attractive, as it would miss other problems in the code.

@belm0
Copy link
Contributor

belm0 commented May 17, 2023

pyi stub support appears to be coming soon (merged to Astroid), so it may resolve this

#4987

@Pierre-Sassoulas
Copy link
Member

@belm0 would you mind trying out the new astroid using pip install git+https://github.com/pylint-dev/astroid.git@main and reporting back ?

@belm0
Copy link
Contributor

belm0 commented May 30, 2023

pylint is not happy with astroid head, so I didn't get very far

File "/.../python3.8/site-packages/pylint/checkers/typecheck.py", line 1688, in _check_invalid_sequence_index
    if subscript.ctx is astroid.Store:
AttributeError: module 'astroid' has no attribute 'Store'

@Pierre-Sassoulas
Copy link
Member

Thank you for checking. My bad, it's going to be checkable but with pip install git+https://github.com/pylint-dev/pylint.git@main and only when we release a new version of astroid with the latest pyi changes and integrate it in pylint probably in #8685

@mbyrnepr2
Copy link
Member

Unfortunately #4987 won't resolve this. #4987 makes it possible to lint .pyi files but it doesn't make it possible to check if a member is defined in a example.pyi file after the member is not found in the example.py file.

@hothanhloc68

This comment was marked as spam.

@mchccc
Copy link

mchccc commented Dec 11, 2023

Is there any update on this? And/or workarounds...

@danieljanes
Copy link

This is blocking us from updating our ProtoBuf dependency, which in turn is blocking us from supporting Python 3.11. Any official update here would be appreciated.

@Pierre-Sassoulas Pierre-Sassoulas added Needs PR This issue is accepted, sufficiently specified and now needs an implementation Help wanted 🙏 Outside help would be appreciated, good for new contributors and removed Needs investigation 🔬 A bug or crash where it's not immediately obvious what is happenning labels Jan 23, 2024
@DanielNoord
Copy link
Collaborator

We would probably add a "astroid brain" for this to work. However, this is not something we would maintain in astroid itself but would rely on a (community maintained)pylint-google plugin. I don't think any of the current maintainers or contributors are actively looking into making such a plugin.

@Pierre-Sassoulas
Copy link
Member

Are we asking for plugins for all the libs that need brains now ? I would be okay with that. But do we move the current astroid brains in their respective plugins for consistency ? Lot of work imo. But valuable to make astroid leaner. Also, I'm not sure there's interest in maintaining pylint-specific-lib-plugin, pylint-tensorflow didn't take off and this is one where there should be a lot of user and a lot of need because there's a lot of C system lib. (I created the skeleton for it and I'm getting spammed by dependabot update for an empty repository that no one contribute to or use).

@DanielNoord
Copy link
Collaborator

Are we asking for plugins for all the libs that need brains now ? I would be okay with that. But do we move the current astroid brains in their respective plugins for consistency ? Lot of work imo. But valuable to make astroid leaner. Also, I'm not sure there's interest in maintaining pylint-specific-lib-plugin, pylint-tensorflow didn't take off and this is one where there should be a lot of user and a lot of need because there's a lot of C system lib. (I created the skeleton for it and I'm getting spammed by dependabot update for an empty repository that no one contribute to or use).

I think so? I don't use tensorflow myself don't see myself contributing quickly, but I think it makes sense to remove as much maintenance burden from astroid as we are already pretty low on maintainers' time.

@llucax
Copy link

llucax commented Aug 28, 2024

In case it helps anyone, we are using mypy and mypy-protobuf to generate the protobuf files. With this, mypy will already check for no-member and no-name-in-module, so we disabled those pylint rules globally and that's it.

llucax added a commit to llucax/frequenz-client-microgrid-python that referenced this issue Aug 29, 2024
We can disable this rule because `mypy` already checks for this kind of
errors and this also fixes a long-standing issue with `pylint` that
can't figure out protobuf generate stuff have some members:

* pylint-dev/pylint#6281

Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
github-merge-queue bot pushed a commit to frequenz-floss/frequenz-client-microgrid-python that referenced this issue Aug 29, 2024
We can disable this rule because `mypy` already checks for this kind of
errors and this also fixes a long-standing issue with `pylint` that
can't figure out protobuf generate stuff have some members:

* pylint-dev/pylint#6281

And now that we disabled this check we can just use the protobuf modules
instead of having to declare one alias per each symbol we need. We did
this before just so we only need to use a `pylint`
`disable=no-name-in-module` one time in the import instead each time we
**used** the symbol.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Help wanted 🙏 Outside help would be appreciated, good for new contributors Lib specific 💅 This affect the code from a particular library Needs astroid Brain 🧠 Needs a brain tip in astroid (then an astroid upgrade) Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
Development

No branches or pull requests

10 participants