栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

用户定义类的类型提示

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

用户定义类的类型提示

前者是正确的 ,如果

arg
接受一个 实例
CustomClass

def FuncA(arg: CustomClass):    #     ^ instance of CustomClass

如果您想要

CustomClass
本身(或子类型),则应编写:

from typing import Type  # you have to import Typedef FuncA(arg: Type[CustomClass]):    #     ^ CustomClass (class object) itself

就像在有关 打字
的文档中写的那样:

**class typing.Type(Generic[CT_co])**

带注释的变量

C
可以接受type的值
C
。相反,带 注释
Type[C]
的变量 可以接受本身是类的值 -具体地说,它将接受的
类对象
C

该文档包含有关

int
该类的示例:

a = 3         # Has type 'int'b = int       # Has type 'Type[int]'c = type(a)   # Also has type 'Type[int]'


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/625874.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号