Typehint (key hint) for python class with __getitem__

Answered

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

2 comments

I don't believe type hints can give you keys in a dictionary.

0

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.

1

Please sign in to leave a comment.