python - How do I return type hinting defined types
问题描述
If I have the following:
def alert(self, text: str, color: str) -> str:
Can I get somehow the specified type of my arguments?
I tried using func.__code__.co_varnames
& inspect.getargspec(func)
without good results.
解决方案
blue_note 的答案不适__future__.annotations
用于 python 3.7 中引入的 ,请改用typing.get_type_hints。
推荐阅读
- css - Laravel 和 Vue 警告问题
- javascript - 将类添加到包含 Dog 1 和其间行的 div
- reactjs - 使用 React Native 和 Hooks 时,状态在 Jest 测试期间没有更新
- angular - 角度路由无法正常工作(路径:'blog/add')
- javascript - 如何使用 jQuery 模板选择选项?
- postgresql - 有什么方法可以将 PostgreSQL 数据库从 Azure 迁移到 AWS RDS PostgreSQL
- c# - 如何一次给多个单元格和列添加边框?
- angular - Chart.js 错误:类型缺少调用签名 '((...items: number[]) => number) | ((...items: ChartPoint[]) => number)' 在 Angular
- c# - Emgu裁剪图像,裁剪错误区域
- android - onPageDataChanged 触发了什么以及发生了什么?