Giter Club home page Giter Club logo

pylint-protobuf's Introduction

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.