I am very new to type hinting in Python 3, and have tried reading and understanding the PEP, and I'm struggling with this.
我很擅长在Python 3中输入提示,并尝试阅读和理解PEP,我正在努力解决这个问题。
I have a function that returns the iterator from re.finditer()
我有一个从re.finditer()返回迭代器的函数
def get_collected_issues(book: Book) -> Iterator:
"""Parse the 'collecting' part of the book description, for series names and issue details.
"""
collecting = get_collecting(book)
return re.finditer(FULL_REGEX, collecting, re.IGNORECASE)
When inspecting at runtime, each iteration of finditer() is a _sre.SRE_Match
object, but that's not importable, so I'm not sure how I can make the return type hint any more specific.
在运行时检查时,finditer()的每次迭代都是_sre.SRE_Match对象,但这不可导入,所以我不确定如何使返回类型提示更具体。
1 个解决方案
#1
2
The typing.re.Match
was added for exactly this reason.
为了这个原因,添加了typing.re.Match。
#1
2
The typing.re.Match
was added for exactly this reason.
为了这个原因,添加了typing.re.Match。