avatar
文章
22
标签
0
分类
21
首页
归档
分类
标签
关于
Decmoe47's BlogPython为类自身添加类型注解
搜索
首页
归档
分类
标签
关于

Python为类自身添加类型注解

发表于2025-03-16|更新于2025-04-07|编程Python
|总字数:43|阅读时长:1分钟|浏览量:

只需from __future__ import annotations

例如:

1
2
3
4
5
from __future__ import annotations

class Position:
def __add__(self, other: Position) -> Position:
...

来源:
https://stackoverflow.com/questions/33533148/how-do-i-type-hint-a-method-with-the-type-of-the-enclosing-class/33533514#33533514

文章作者: Decmoe47
文章链接: https://decmoe47.github.io/p/944e0939/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 Decmoe47's Blog!
上一篇
prettier格式化所有文件
(详细代码请查看正文) 然后在package.json中写入: (详细代码请查看正文)
下一篇
ts引用别名(绝对引用)转换为相对引用(解决tsc无法转换引用别名)
(详细代码请查看正文) 然后在package.json中写入: (详细代码请查看正文)

评论
最新文章
记录搭建博客的过程(Hexo+Butterfly+Github Actions+Github Pages)2025-03-17
go缓解连续多个iferr的一个办法2025-03-16
解决Goland换主题但代码看起来五颜六色太乱的问题2025-03-16
Typescript使用ts-node报错Could not find a declaration file for module2025-03-16
Could not read source map for xxx2025-03-16
go通过github action自动部署到服务器2025-03-16
©2025 By Decmoe47
框架 Hexo 7.3.0|主题 Butterfly 5.3.5
搜索
数据加载中