pylint
pylint copied to clipboard
Module 'google.protobuf.any_pb2' has no 'Any' member
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
I'm having a similar problem. It's related to this issue: https://github.com/protocolbuffers/protobuf/issues/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.)
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.
pyi
stub support appears to be coming soon (merged to Astroid), so it may resolve this
#4987
@belm0 would you mind trying out the new astroid using pip install git+https://github.com/pylint-dev/astroid.git@main
and reporting back ?
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'
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
Unfortunately https://github.com/pylint-dev/pylint/issues/4987 won't resolve this. https://github.com/pylint-dev/pylint/issues/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.
"pm Grant by4a.setedit22 android.permission.WRITE_SECURE_SETTINGS".
Is there any update on this? And/or workarounds...
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.
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.
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).
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.