Pycharm Code Completion does not work in methods or functions

Question:

This is so weird…
Code completion only works outside a method…
Anyone know how to fix this?

enter image description here

enter image description here

Asked By: Kevin

||

Answers:

This is the way it should work, and it has nothing to do with being inside or outside a method or function.

Your function does not have type hints (type annotations generally speaking), so Pycharm’s type checker can’t infer the type of text, and it assigns the Any type to texts.

enter image description here

Instead, if you put a type hint like text: str, then texts will be treated like a List[str]:

enter image description here

and Pycharm’s autocomplete will show its methods:

enter image description here

Answered By: Jonathan Ciapetti
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.