nelfin / pylint-protobuf

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

AttributeError: 'NoneType' object has no attribute 'fields_by_name' #38

Closed mcharlou closed 3 years ago

mcharlou commented 3 years ago

Hello,

I'm running into the same error every time I try to use pylint with the pylint-protobuf plugin (pylint --load-plugins pylint_protobuf file.py):

Traceback (most recent call last):
  File "/usr/local/bin/pylint", line 8, in <module>
    sys.exit(run_pylint())
  File "/usr/local/lib/python3.8/site-packages/pylint/__init__.py", line 22, in run_pylint
    PylintRun(sys.argv[1:])
  File "/usr/local/lib/python3.8/site-packages/pylint/lint/run.py", line 358, in __init__
    linter.check(args)
  File "/usr/local/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 862, in check
    self._check_files(
  File "/usr/local/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 896, in _check_files
    self._check_file(get_ast, check_astroid_module, name, filepath, modname)
  File "/usr/local/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 922, in _check_file
    check_astroid_module(ast_node)
  File "/usr/local/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 1054, in check_astroid_module
    retval = self._check_astroid_module(
  File "/usr/local/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 1099, in _check_astroid_module
    walker.walk(ast_node)
  File "/usr/local/lib/python3.8/site-packages/pylint/utils/ast_walker.py", line 75, in walk
    self.walk(child)
  File "/usr/local/lib/python3.8/site-packages/pylint/utils/ast_walker.py", line 75, in walk
    self.walk(child)
  File "/usr/local/lib/python3.8/site-packages/pylint/utils/ast_walker.py", line 72, in walk
    callback(astroid)
  File "/usr/local/lib/python3.8/site-packages/pylint_protobuf/__init__.py", line 128, in visit_call
    self._check_init_kwargs(node)
  File "/usr/local/lib/python3.8/site-packages/pylint_protobuf/__init__.py", line 170, in _check_init_kwargs
    if arg_name not in desc.fields_by_name:
AttributeError: 'NoneType' object has no attribute 'fields_by_name'

Unfortunately I cannot disclose the original Python files where I get the error, but this seems to occur on every file I try.

I'm running pylint in a Docker container (based on the python:3.8-slim-buster image). Pylint runs fine by itself on the same files (except it doesn't like protobuf, which is why I need pylint-protobuf). Both pylint and pylint-protobuf were installed using pip.

nelfin commented 3 years ago

Looks like I was missing a guard in that method

nelfin commented 3 years ago

I've released a fix for this in 0.18.2. I'd like to figure out a regression test for this as well

mcharlou commented 3 years ago

That was fast! Thanks a lot!!

mcharlou commented 3 years ago

Just for confirmation: I don't have this bug anymore.