Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No warning at undefined variables in PyCharm Community 2017.2

I have this piece of code in a Python module open in PyCharm Community Edition 2017.2.

class Sample(object):
    def __init__(self):
        self.prop1 = 5
        self.prop2 = 10

    def method1(self):
        return foo

    def do_work(self):
        not_defined_func()


s = Sample()
s.method1()

bar = call_func

The IDE doesn't give any warnings on some fairly serious issues:

  1. The returned variable foo has not been defined.
  2. I assign not defined variable call_func to the variable bar.
  3. I call not defined function not_defined_func inside the method do_work.

How do I enable PyCharm to highlight these things? I have a fresh installation of PyCharm and have all the Inspections enabled in File > Settings > Editor > Inspections > Python.

like image 576
Alex Tereshenkov Avatar asked Oct 05 '17 10:10

Alex Tereshenkov


People also ask

How do you fix a undefined variable error in Python?

There are a few ways to fix an undefined variable: (1) You can rename the variable or variable set so that it matches what you have used in the topic; (2) you can re-insert the variable in the topic so that it uses an existing variable set/variable name, (3) you can add the undefined variable to the project as a new ...

What is an undefined variable in PHP?

This error means that within your code, there is a variable or constant which is not set. But you may be trying to use that variable. The error can be avoided by using the isset() function.


1 Answers

See which python interpreter is enabled go to preference > Project > Project Interpreter. Set python interpreter and then apply it. Also check if inspections are enabled.

like image 138
ZApatel Avatar answered Oct 27 '22 06:10

ZApatel