Typehint (key hint) for python class with __getitem__
已回答
Hello,
I have class in python with map of values, which can be use for calling get item on that class. In Pycharm i want typehint fot list of keys in this map. Is there any possibility to do that? What do i want:
class MyOwnClass:
map = { 'first' : 1, 'second' : 2}
def __getitem__(item):
return self.map[item]
m = MyOwnClass()
m[' ']
^---------- At this place i want to press CTRL+SPACE and i want to get list of available keys.
Is there any solution for this? Or i must create some plugin for this.
Thank you so much
请先登录再写评论。
I don't believe type hints can give you keys in a dictionary.
Hi Dragonwilson194! Type hints are indeed irrelevant here. Meanwhile, PyCharm is able to provide completion for dictionary keys in simple cases, e.g.
unfortunately, your example is too complex and isn't supported. I believe PY-21079 request is relevant, feel free to vote for it.