How do I document :rtype: for a function that returns multiple possible data types? [duplicate]

空扰寡人 提交于 2019-12-03 06:26:08

You can use 'or' explicitly in the rtype

:rtype: collections.defaultdict or dict or list

variant

:rtype: collections.defaultdict | dict | list
Cpt_Jauchefuerst

I think I just found out myself by stumbling over a similar question: How to specify multiple return types using type-hints

:rtype: can be

:rtype: Union[collections.defaultdict, dict, list]
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!