PyCharm: Code Completion doesn't work if variable was defined in other function

Viewed 131

I am using PyCharm Community version 2018.2.4.

When I define a local variable, for example a string, in my main() method and pass the variable as parameter to a function, PyCharm doesn't recognize this variable as string and it doesn't provide any code completion. This happens also for other types. For variables defined in the same function, code completion works as expected!

pycharm - no code completion

Has anybody run into the same issue and know how to solve this?

2 Answers

Happens in Eclipse too, the IDE will not recognize an attribute of an object for a while, try to execute the code a few times and maybe restart the IDE. That should do.

You can use type annotations so it knows it's a string like so:

def validate_input(input_path: str, output_path):
    input_path.(proper_string_functions)
Related