pycharm - How to specify that a parameter is a list of specific objects in Python docstrings -
i using docstrings in python specify type parameters when projects beyond size.
i'm having trouble finding standard use specify parameter list of specific objects, e.g. in haskell types i'd use [string] or [a].
current standard (recognisable pycharm editor):
def stringify(listofobjects): """ :type listofobjects: list """ return ", ".join(map(str, listofobjects))
what i'd prefer:
option 1
def stringify(listofobjects): """ :type listofobjects: list<object> """ return ", ".join(map(str, listofobjects))
option 2
def stringify(listofobjects): """ :type listofobjects: [object] """ return ", ".join(map(str, listofobjects))
i suppose wasn't great example - more relevant use case 1 objects in list must of specific type.
better example
class food(object): def __init__(self, calories): self.calories = calories class apple(food): def __init__(self): super(self, 200) class person(object): energy = 0 def eat(foods): """ :type foods: [food] # not recognised editor """ food in foods: energy += food.calories
so, other fact i'm getting hungry, example illustrates if called list of wrong kind of object, code break. hence importance of documenting not needs list, needs list of food.
related question how can tell pycharm type parameter expected be? please note i'm looking more specific answer 1 above.
in comments section of pycharm's manual there's nice hint developer:
#: :type: dict of (str, c) #: :type: list of str
it works me pretty well. makes me wonder what's best way document parametrized classes in python :).
Comments
Post a Comment