pylint-dev / pylint

It's not just a linter that annoys you!
https://pylint.readthedocs.io/en/latest/
GNU General Public License v2.0
5.26k stars 1.12k forks source link

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

Open PhilippSelenium opened 2 years ago

PhilippSelenium commented 2 years ago

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

mbmccoy commented 2 years ago

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.)

belm0 commented 1 year ago

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 commented 1 year ago

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

4987

Pierre-Sassoulas commented 1 year ago

@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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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.

hothanhloc68 commented 11 months ago

"pm Grant by4a.setedit22 android.permission.WRITE_SECURE_SETTINGS".

mchccc commented 9 months ago

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

danieljanes commented 8 months ago

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.

DanielNoord commented 8 months ago

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 commented 8 months ago

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 commented 7 months ago

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 commented 4 weeks ago

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.