I am learning Python OOP and Composition. In this experiment i have created 2 class, first Account class that maintains deposit, withdraw, info and etc functions for user. Also i have created Bank class (as composition for Account class). Here in my Bank class i created dict() (self.accountsDict = {}) data type for storing Account objects for particular number as keyword of dictionary (self.nextAccountNumber = 0).
But i have problem that i have no idea how to handle it. The problem is that if i call properties of oAccount via dot Pycharm suggests available methods and attributes. But doing that through dictionary dose not suggest anything. i have reset Pycharm IDE settings, tried to do that via VsCode same result. Any idea please!!
from Account import *
class Bank():
def __init__(self):
self.accountsDict = {}
self.nextAccountNumber = 0
def createAccount(self, theName, theStartingAmount, thePassword):
oAccount = Account(theName, theStartingAmount, thePassword)
newAccountNumber = self.nextAccountNumber
self.accountsDict[newAccountNumber] = oAccount
self.accountsDict[newAccountNumber].WHY IT DOES NOT SUGGEST AVAILABEL METHODS
# Increment to prepare for next account to be created
self.nextAccountNumber = self.nextAccountNumber + 1
return newAccountNumber
You can use typing library to explicitly specify your dictionary to contain specific variable types. Most IDEs (checked on VSCode) will be able to take this into account and treat the variable as a specified type during static type check.
d: dict[int, str] = {}
d["foo"] # type hints for str type show up