0

Summary

Pylint is complaining of undefined variables in class declarations and the following functions. If I comment out the class declarations, the functions are still being highlighted and I am unsure why.

Environment

OS: Suse Leap 42.3
Editor: vscode 1.38
Python: 3.4.6
Pylint: 1.4.4
Pylint Args: ["--load-plugin", "pylint_protobuf", "--enable=F,E,W"]

Reproduction case

#!/usr/bin/env python3
'''Dummy doc string'''

from ctypes import * # pylint: disable=unused-wildcard-import

class BOX(Structure):
    _fields_ = [("x", c_float),
                ("y", c_float),
                ("w", c_float),
                ("h", c_float)]

def example(a, b):
    c = str(a + b)
    print(c)

Which produces the following errors/warnings

Undefined variable 'Structure' pylint(undefined-variable) [6, 11]
Undefined variable 'a' pylint(undefined-variable) [13, 13]
Undefined variable 'b' pylint(undefined-variable) [13, 17]
Undefined variable 'c' pylint(undefined-variable) [14, 11]
Locally disabling unused-wildcard-import (W0614) pylint(locally-disabled) [4,1]

If I hover over Structure I can see class PyCStructType(), likewise if I hover over c I can see c: str, so the datatypes are known.

Questions

  • Why does the above code produce pylint errors? (I expect to only see a warning for locally disabling unused wildcard imports)
  • Is this issue specific to my environment? (older version of python, etc.)

N.b. I do not want to use # pylint: disable=undefined-variable

Roqux
  • 608
  • 1
  • 11
  • 25
  • A linter that only works on one file at a time can't tell what names are defined by a wildcard import, so I'm not at all surprised that it's concerned about `Structure`. I have no idea why it's confused about `a`, `b`, and `c` though. I'd have expected it to also be confused about `c_float` (perhaps repeatedly), since I imagine that also comes from `ctypes`. You may be able to satisfy it by using a more explicit import statement: `from ctypes import Structure, c_float` (though whether that will fix `a`, `b` and `c` I have no idea). – Blckknght Sep 11 '19 at 23:08

0 Answers0