python - 用于静态方法参数的 Python 集类
问题描述
尝试为静态方法参数指定类时,例如:
class A:
@staticmethod
def staticm(param1: A):
return 1
它引发了一个错误,即'A' is not defined
.
为什么我不能这样做?有漏洞吗?
我可以检查isinstance
...但是为什么在python中不允许这样做?
解决方案
这个答案基于@saquintes 的评论。
解决方案:将类添加A
为字符串'A'
class A:
@staticmethod
def staticm(param1: 'A'):
return 1
推荐阅读
- javascript - Vue.js b-table 插槽未正确显示
- android - 如何修复:java.io.FileNotFoundException:没有内容提供者
- vb.net - 正确使用DataGridView?
- google-apps-script - 如何找出创建的工作表的顺序?
- python - 为什么 Django Rest 框架不显示发布的纬度?
- java - 由于 InvalidDefinitionException,javamoney 的 CurrencyUnit 不能用作字段类并被 Jackson 反序列化
- c - Pthread_join() 挂在线程数组上
- android - 如何将 AudioStream/AudioGroup 与本地 Wifi-Hotspot 一起使用
- shell - spark 启动 dir 正在工作,但 spark-shell 没有得到 lanuch 出现错误 'spark-shell' 无法识别
- excel - 如何通过按一下按钮隐藏和取消隐藏工作表?