[英]In python typing in the Class method __init__ the argument type annotation I have for 1 attribute is: Callable = None, what does the annotation state?
Class 中的init function 注释如下:
def __init__(self, directory: str, transforms: Callable = None, extension: str = '.jpg'):
问题是Callable = None
指的是什么。
按照惯例,如果transforms
- 参数注释意味着接受一个 Callable(即函数),那么需要定义输入参数以及 output,例如它可以是: transforms: Callable[[int,int], int]
其中[int,int] would be the function parameters as input, and the latter
int` 将是返回值。 但在这里情况并非如此。
在这种情况下, Callable
注释期望什么作为输入和返回?
一个普通的 Callable 等价于 Callable[..., Any],然后又等价于 collections.abc.Callable。
在没有任何关于 class 的信息或 class 做什么的情况下,很难说出这个 function 和 output 会接受什么作为输入。 这完全取决于 class 的作用,您可能应该阅读 class 的文档。
通过查看extension
的默认值, class 需要.jpg
文件。 如果它是像pillow
这样的图形或图像处理库,则可调用对象可能需要获取某种图像数据。
然而,正如我所说,没有更多信息就无法判断。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.