'VSCode Python autocompletion not working on some classes only
When using autocompletion in VSCode in my python project, it works very well except for one class and I cannot figure out why.
The class is coming from a module database which contains 3 classes total: DatabaseClient, Database, Collection
DatabaseClient has a get_database() method which returns a Database object.Database has a get_collection() method which returns a Collection object.Collection has several methods.
The autocompletion works as intended on the DatabaseClient & Database objects, but not at all on the Collection object.
The code below works and give the expected results (line 15 and 20 of the screenshot results match), but not the autocompletion while editing as stated above.
import lib.database as database
print( database.DatabaseClient().get_database('business').get_collection('reviews').find() )
client = database.DatabaseClient()
db = client.get_database(client.list_database_names()[0])
coll = db.get_collection(db.list_collection_names()[0])
print(coll.find())

Tried to reload VSCode, unload and reload the python extensions.
Tried to uninstall and re-install the python extensions.
Tried to change the name of my module.
Tried to change the name of the class.
Tried to change the name of the method of the Collection class.
Tried using single line command line 3 and noticed it worked this way.
Solution 1:[1]
Found out the solution. The problem comes from not using typing in the method headers. Once I added proper typing, the autocompletion worked everywhere as expected.
def get_database(self, database_name: str) -> Database:
def get_collection(self, collection_name: str) -> Collection:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Maien_ |
