Reputation: 1
I'm implementing a repository pattern in Python for my project and using VSCode as my IDE. However, I'm having trouble with method autocompletion for instances of my repository classes. When I type db.user. or db.suggestion., I don't see any suggestions for available methods like create, get, etc.
class Database:
def __init__(self, db_file: str):
"""
Initialize database.
:param db_file: Path to database file.
"""
self.db_file = db_file
self.user = UserRepository(db_file)
self.suggestion = SuggestionRepository(db_file)
self.admin_action = AdminActionRepository(db_file)
class UserRepository:
def __init__(self, db):
self.db = db
self.lock = asyncio.Lock()
async def create(self, user_id, first_name, last_name):
pass
After entering db.user. there are no hints of functions of the UserRepository subclass.
I tried this method:
self.user: UserRepository = UserRepository(db_file)
self.suggestion: SuggestionRepository = SuggestionRepository(db_file)
self.admin_action: AdminActionRepository = AdminActionRepository(db_file)
However, it does not give the desired result, and the code is:
db.user.UserRepository.create()
instead of the expected db.user.create()
Upvotes: 0
Views: 25
Reputation: 1
In my stupidity, I didn't notice that it was not the class that was imported, but the file.
Solution: just import the class.
Upvotes: 0