I'm building a class with methods that take dictionaries as inputs but Pycharm displays a warning.
''' Expected type 'TestClass', got 'Dict[str, int]' instead less... (⌘F1) Inspection info: This inspection detects type errors in function call expressions. Due to dynamic dispatch and duck typing, this is possible in a limited but useful number of cases. Types of function parameters can be specified in docstrings or in Python 3 function annotations '''
class TestClass:
def __getitem__(self, index):
return self[index]
def get_keys(self):
return list(self.keys())
dict_input = {'a':123, 'b':456}
TestClass.get_keys(dict_input)
So I get the warning here:
TestClass.get_keys(dict_input)
What does this warning mean and what's the approach to fix it?
get_keysis an instance method, you're supposed to call it on an instance of the class. But there is nowhere in your code that accepts a dict, so it's my clear where the keys are supposed to be coming from. - Daniel Rosemanget_key()is a method - it would normally be called on an instance ofTestClass, NOTTestclassitself. It would take no parameters other than the implicitselfpassed to all methods, so I have no idea what that dict you're passing is supposed to do. - jasonharper