nelfin / pylint-protobuf

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

Plugin cannot handle module-level exports #23

Closed xSAVIKx closed 3 years ago

xSAVIKx commented 4 years ago

To simplify usage of generated Python protos I do export specific messages from the proto package inside __init__.py like this:

from thumbnails_proto.thumbnails_pb2 import RotationAngle, ImageFormat, ImageSize, GcsPath
from thumbnails_proto.thumbnails_pb2 import Operation, ScaleAction, RotateAction, ConvertAction
from thumbnails_proto.thumbnails_pb2 import JpegConversion, WebpConversion, PngConversion

The _pb2 files themselves are in the thumbnails_proto package. With such a setup, the plugin is not able to recognize proto definitions.

Such a custom init file allows me to import proto definitions like this: from thumbnails_proto import Operation instead of import thumbnails_proto.thumbnails_pb2 import Operation.

nelfin commented 4 years ago

Hi @xSAVIKx, thanks for the report. I see what you mean, we don't check re-exported names from protobuf modules since the linter checks top-down ("where did this symbol come from") instead of bottom-up ("where are these protobuf classes used"). IIRC there's a guard against checking imports from modules (aliased or otherwise) that don't end in _pb2, I'll see what the state of the code is around there and how easy it would be to relax that and check nested imports.

nelfin commented 3 years ago

This should be fixed in the latest master but hasn't made it into a released version yet

nelfin commented 3 years ago

@xSAVIKx, this fix has been release in 0.14. Sorry for the wait! Can you confirm that everything is okay?

nelfin commented 3 years ago

I've confirmed on my end that this is fixed, I'll close this issue in a couple of days if there's no update.

xSAVIKx commented 3 years ago

@nelfin thx a lot for the fix. It works fine now! I'll close the issue.