python - mypy 键入导致意外回溯
问题描述
我正在尝试解决此GitHub 问题中描述的问题(“具有函数字段的类错误地认为第一个参数是 self”)。
from dataclasses import dataclass
from typing import TypeVar, Generic, Any, Iterable, List
T = TypeVar("T")
# See https://github.com/python/mypy/issues/5485
@dataclass
class Box(Generic[T]):
inner: T
@property
def unboxed(self) -> T:
return self.inner
不过,我遇到了这样的回溯:
但是,在从另一个模块导入 (仅(!))上面的代码时,我遇到了这样的回溯:
(py) sugarline:~/src/oss/ormsnack write-compile-eval
Traceback (most recent call last):
[.....]
File "/Users/jacob/src/oss/ormsnack/ormsnack/ng_desc.py", line 8, in <module>
from kingston.kind import Box # type: ignore
File "kingston/kind.py", line 12, in <module>
AttributeError: attribute '__dict__' of 'type' objects is not writable
不过,谷歌搜索只会让我陷入似乎已经过时的旧错误(https://bugs.python.org/issue38099、https://github.com/man-group/arctic/issues/17)等。
有没有人能够找出解决方法?
解决方案
推荐阅读
- java - 添加减去分钟谷歌日历api
- python - 为什么在 Zapier 中使用此代码时会出现 Runtime.MarshalError?
- button - 溢出的 RenderFlex 颤动
- java - 禁用字段上的 Tapestry 验证
- javascript - Nothing was returned from render when using prototype
- python - 使用结构化数组在 numpy 数组中命名轴
- ajax - Woocommerce 结帐页面 - Ajax 刷新运费
- python - 线程阻塞了控制台
- matlab - 在左侧对齐子图 ylabel
- iis - IIS:可导出 SSL 证书请求和私钥