nelfin / pylint-protobuf

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

imported message definitions not supported #25

Closed sagar-infinitus-ai closed 4 years ago

sagar-infinitus-ai commented 4 years ago

I'm not sure if this is the same as https://github.com/nelfin/pylint-protobuf/issues/10 - if it is, sorry for the dup! message types imported into other protos will always raise E5901. Example: motorcycles.proto:

syntax = "proto3";

package bikes;

import "engines.proto";

message Motorcycle {
    string brand = 1;
    string name = 2;
    Engine engine = 3;
}

engines.proto:

syntax = "proto3";

package bikes;

enum EngineType {
    TWO_STROKE = 0;
    FOUR_STROKE = 1;
}

message Engine {
    // EngineType engine_type = 1;
    int32 displacement = 2;
}

Code:

from motorcycles_pb2 import Motorcycle
from engines_pb2 import Engine, EngineType

m = Motorcycle()
m.name = "Monster"
m.engine.displacement=300

pylint error:

motorcycles/__main__.py:6:0: E5901: Field 'engine' does not appear in the declared fields of protobuf-generated class 'motorcycles_pb2.Motorcycle' and will raise AttributeError on access (protobuf-undefined-attribute)

This error is not reported if all messages are declared in a single .proto file.

versions: protobuf: 3.12.2 pylint-protobuf: 0.12 pylint: 2.5.2

nelfin commented 4 years ago

Hi @sagar-infinitus-ai, it does look like this is a duplicate of #10. Though the wording doesn't go into too much detail, the linked test case covers this exact behaviour in fixture/import.proto:

syntax = "proto2";

package test;
import "child.proto";
message Parent {
  required Child child = 1;
}

However, I just wanted to say thanks for such a great report.

On Wed., 3 Jun. 2020, 09:45 Sagar Gokhale, notifications@github.com wrote:

I'm not sure if this is the same as #10 https://github.com/nelfin/pylint-protobuf/issues/10 - if it is, sorry for the dup! message types imported into other protos will always raise E5901. Example: motorcycles.proto:

syntax = "proto3";

package bikes;

import "engines.proto";

message Motorcycle { string brand = 1; string name = 2; Engine engine = 3; }

engines.proto:

syntax = "proto3";

package bikes;

enum EngineType { TWO_STROKE = 0; FOUR_STROKE = 1; }

message Engine { // EngineType engine_type = 1; int32 displacement = 2; }

Code:

from motorcycles_pb2 import Motorcycle from engines_pb2 import Engine, EngineType

m = Motorcycle()m.name = "Monster" m.engine.displacement=300

pylint error:

motorcycles/main.py:6:0: E5901: Field 'engine' does not appear in the declared fields of protobuf-generated class 'motorcycles_pb2.Motorcycle' and will raise AttributeError on access (protobuf-undefined-attribute)

This error is not reported if all messages are declared in a single .proto file.

versions: protobuf: 3.12.2 pylint-protobuf: 0.12 pylint: 2.5.2

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/nelfin/pylint-protobuf/issues/25, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABSH3JTXPOVB6E6DT4UGP3RUWFIXANCNFSM4NRFLVCQ .

sagar-infinitus-ai commented 4 years ago

Awesome. Thanks for looking in to it! I'm going to close this.