Skip to main content

A plugin for making Pylint aware of the fields of protobuf-generated classes

Project description

pylint-protobuf

pylint-protobuf is a Pylint plugin for making Pylint aware of generated fields from Protobuf types.

Install

Install from PyPI via:

pip install pylint-protobuf

Add or update pylintrc to load pylint-protobuf:

[MASTER]
load-plugins=pylint_protobuf

Example

$ cat <<EOF >person.proto
message Person {
  required string name = 1;
}
EOF
$ protoc person.proto --python_out=.
$ cat <<EOF >readme.py
from person_pb2 import Person
p = Person('all arguments must be kwargs')
p.invalid_field = 'value'
p.name = 123
EOF
$ pip install pylint-protobuf
$ pylint --load-plugins=pylint_protobuf readme.py
************* Module readme
readme.py:2:4: E5904: Positional arguments are not allowed in message constructors and will raise TypeError (protobuf-no-posargs)
readme.py:3:0: E5901: Field 'invalid_field' does not appear in the declared fields of protobuf-generated class 'Person' and will raise AttributeError on access (protobuf-undefined-attribute)
readme.py:4:0: E5903: Field "Person.name" is of type 'str' and value 123 will raise TypeError at runtime (protobuf-type-error)

Supported Python Versions

pylint-protobuf supports Python 3.5 at a minimum.

Known Issues

pylint-protobuf does not currently support the following concepts:

  • Some features of extensions: non-nested extensions, HasExtension(), ClearExtension(), type checking

Alternatives

mypy-protobuf

A protoc compiler plugin for generating .pyi stubs from .proto files. Fully-featured and well supported, a useful extension to a mypy workflow. May be better suited to your usecase if you control the entire pipeline. May not be suited if you are a downstream consumer of generated _pb2.py modules with no access to the original .proto definitions, in which case pylint-protobuf may be better suited for your use.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pylint-protobuf-0.21.0.tar.gz (14.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pylint_protobuf-0.21.0-py2.py3-none-any.whl (15.6 kB view details)

Uploaded Python 2Python 3

File details

Details for the file pylint-protobuf-0.21.0.tar.gz.

File metadata

  • Download URL: pylint-protobuf-0.21.0.tar.gz
  • Upload date:
  • Size: 14.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.7.0 requests/2.25.1 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.5.9

File hashes

Hashes for pylint-protobuf-0.21.0.tar.gz
Algorithm Hash digest
SHA256 c643f796db9d0c85fc597803bc92c920c0a3eb1f02acff210518589aef79112f
MD5 a26171054b61190a8eddb7e0fa4674ee
BLAKE2b-256 0d6deece5070419848acf648153be2b561662abeae5428ef19e12f27a6888fd6

See more details on using hashes here.

File details

Details for the file pylint_protobuf-0.21.0-py2.py3-none-any.whl.

File metadata

  • Download URL: pylint_protobuf-0.21.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 15.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.7.0 requests/2.25.1 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.5.9

File hashes

Hashes for pylint_protobuf-0.21.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 b334ba32f40a579d1f8b44f3ab7a495f2553b204df6f628ee20e53db4d5a9b17
MD5 13f4245fd0fe164cb7bfe48583ae0b3e
BLAKE2b-256 8c00a819c6295a92734fa9c9ea12a4ae28d17eb97a025a19eecf4302c9cc2380

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page