lucrib
lucrib

Reputation: 459

How to tell the IDE a method returns a list containing only a specific type of Objects in Python?

I'm using the PyCharm Community Edition on development.

I know I can use python docstrings to set a return with :rtype:.

But how can I tell that a method returns a list with specific objects type and then be able to use autocomplete after that.

class MyObject:
    def method_1(self):
        do_something()
    def method_2(self):
        do_something()

class ReturnListOfObjects:
    def return_list_of_MyObjects():
    """
    :rtype: (here I usually put just list, but can not use autocomplete after)
    """

Upvotes: 1

Views: 85

Answers (1)

masnun
masnun

Reputation: 11916

According to this link - https://www.jetbrains.com/pycharm/help/type-hinting-in-pycharm.html#d314357e162, it should be:

list[MyObject]

Upvotes: 1

Related Questions