nelfin / pylint-protobuf

A plugin for making Pylint aware of the fields of protobuf-generated classes
MIT License
29 stars 12 forks source link

Consider wellknowntypes again #37

Closed mabrowning closed 3 years ago

mabrowning commented 3 years ago

The test_wellknowntypes passes, but the feature doesn't actually work:

$ cat test.py
"""
Any test
"""
from google.protobuf.any_pb2 import Any

a = Any()
a.Pack()

$ pylint test.py
************* Module test
test.py:7:0: E1101: Instance of 'Any' has no 'Pack' member (no-member)

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

Looks like nothing checks the cls_def for membership in the well known types with the new astroid refactor (which is otherwise great). This PR attempts to rectify that, though I feel like there should be a better way of finding the absolute name/module name a class is defined in...

nelfin commented 3 years ago

The test_wellknowntypes passes, but the feature doesn't actually work

Yeah, that would be because TestWellKnownTypes only instantiates the pylint_protobuf checker, whereas the no-member warnings are raised by the inbuilt pylint typecheck checker. When testing the integration of components like this, I've resorted to writing end-to-end tests like the one in test_issue32.py:

def test_membership_on_map_types(warnings_mod, linter_factory):
    linter = linter_factory(
        register=pylint_protobuf.register,
        disable=['all'], enable=['unsupported-membership-test',
                                 'unsubscriptable-object'],
    )
    linter.check([warnings_mod])
    # expected_messages = [
    #     pylint.checkers.typecheck.MSGS['E1135'][0] % ('m.map_test',),
    #     pylint.checkers.typecheck.MSGS['E1136'][0] % ('m.map_test',),
    # ]
    actual_messages = [m.msg for m in linter.reporter.messages]
    assert not actual_messages

The WKT test cases were written some time before I started handling these kinds of tests.