如何在我的自己的Python包中正确使用类型提示

huangapple go评论54阅读模式
英文:

How do i correctly type hint in my own python package

问题

Im currently creating my first own package in python using twine. In my test folder the autocompletion in pycharm works like a charm. See 1 2

但如果上传到testpypl并下载到新项目,它就不再起作用了 3 4

Currently my method looks like this:

目前我的方法如下:

async def championships(self, game: Game, type: MatchType = MatchType.ALL, offset: int = 0,
limit: int = 10) -> Collection[Championship]:

Do I need to add some special docstrings for this to work?
我需要添加一些特殊的文档字符串才能使它起作用吗?
I saw other packages with this kind of docstrings:

我看到其他包中有这种类型的文档字符串:

"""
:param summoner_id: summoner ID
:return: list of masteries for the given summoner
:type summoner_id: str
:rtype: List[:class:`~types.ChampionMasteryDto`]
"""

But its not working for me.
但对我来说不起作用。

英文:

Im currently creating my first own package in python using twine. In my test folder the autocompletion in pycharm works like a charm. See 1 2

But if uploaded to testpypl and downloaded to a new project its not working anymore 3 4

Currently my method looks like this:

async def championships(self, game: Game, type: MatchType = MatchType.ALL, offset: int = 0,
                        limit: int = 10) -> Collection[Championship]:

Do I need to add some special docstrings for this to work?
I saw other packages with this kind of docstrings:

"""
:param summoner_id: summoner ID
:return: list of masteries for the given summoner
:type summoner_id: str
:rtype: List[:class:`~types.ChampionMasteryDto`]
"""

But its not working for me.

答案1

得分: 1

感谢 @chepner 和 @Mikko,我知道这与文档字符串无关。所以我检查了所有其他的东西,才意识到我导入的方式不正确。我进行了更正,现在它可以工作:

from src.package_name.types import *
from .types import *
英文:

Thanks to @chepner and @Mikko i knew it had nothing to do with the doc string. So i checked all the other things and just realized i did the import wrong. I changed it and now it works:

from src.package_name.types import *
from .types import *

huangapple
  • 本文由 发表于 2023年2月8日 21:31:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/75386524.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定