nelfin / pylint-protobuf

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

Multiple imports with aliasing may cause AssertionError #18

Closed nelfin closed 5 years ago

nelfin commented 5 years ago

Importing a module from a package multiple times with different aliases can cause an AssertionError by due to the assumption that importing a module can only increase the amount of names in the global namespace. To the best of my knowledge this is still true, but handling of imported names with aliases is improperly tracked.

This can be reproduced by the following case:

from package import module_pb2
from package import module_pb2 as foo
nelfin commented 5 years ago

@Kami, is this the case that you were seeing? I tried to reverse-engineer the behaviour that might cause the stack trace that you posted in #17

Kami commented 5 years ago

Yep, I belive that's indeed the root cause (we import module multiple times under a different alias and location).

Thanks for such a quick turn around and a fix. I will look into testing it shortly.

Kami commented 5 years ago

Thanks, I just confirmed the fix is working :+1:

Kami commented 5 years ago

There do appear to be some other issues related to struct field types and referenced fields, but I will open a separate issue for that.