pylint icon indicating copy to clipboard operation
pylint copied to clipboard

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

Open PhilippSelenium opened this issue 2 years ago • 14 comments

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 avatar Apr 12 '22 11:04 PhilippSelenium

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

mbmccoy avatar May 07 '22 19:05 mbmccoy

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 avatar Mar 17 '23 05:03 belm0

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

#4987

belm0 avatar May 17 '23 05:05 belm0

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

Pierre-Sassoulas avatar May 20 '23 18:05 Pierre-Sassoulas

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'

belm0 avatar May 30 '23 07:05 belm0

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

Pierre-Sassoulas avatar May 31 '23 19:05 Pierre-Sassoulas

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.

mbyrnepr2 avatar Jun 01 '23 09:06 mbyrnepr2

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

hothanhloc68 avatar Oct 12 '23 16:10 hothanhloc68

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

mchccc avatar Dec 11 '23 14:12 mchccc

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.

danieljanes avatar Jan 18 '24 10:01 danieljanes

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.

DanielNoord avatar Jan 30 '24 13:01 DanielNoord

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

Pierre-Sassoulas avatar Jan 30 '24 13:01 Pierre-Sassoulas

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.

DanielNoord avatar Jan 31 '24 19:01 DanielNoord