如何键入对NamedTuples的PyFunctional序列进行注释?

时间:2018-12-29 12:03:40

标签: python-3.x functional-programming

我想输入一个注释函数,该函数返回NamedTuples的PyFunctionalseq(序列)。

from functional import seq
from typing import NamedTuple, List

class SomeNamedTuple(NamedTuple):
    number: int
    string: str

DataType = List(SomeNamedTuple)

data = [
    SomeNamedTuple(1, 'one'),
    SomeNamedTuple(2, 'two'),
]

def function_returning_sequence(data):
    sequence = seq(data)
    return sequence

调查返回序列的类型时(例如,在IPython / Jupyter笔记本中),结果为functional.pipeline.Sequence。但是我该如何定义类型来对函数进行注释,如下所示:

ReturnType = ???    

def function_returning_sequence(data: DataType) -> ReturnType:
    ....

使用error: Invalid type "<package>.<module>.ReturnType"进行检查时,将类型定义为简单序列会产生mypy

from functional.pipeline import Sequence

ReturnType = Sequence

def function_returning_sequence(data: DataType) -> ReturnType:
    ....

0 个答案:

没有答案