【发布时间】:2021-11-28 17:33:13
【问题描述】:
在编写代码时,我遇到了表达 ~<type> 类型的 linter(其中 <type> 不是 <type>literature 的类型)。 self 就是一个例子。
class A:
def foo(self):
reveal_type(self) # reveals "~A"
我假设这意味着“A 或A 的子类”;但是,我无法在网上找到有关它的任何信息。
另外,你不能在代码中使用这种语法:
a: ~A # raises an exception: TypeError: bad operand type for unary ~: 'type'
如果a 会被泄露,那就是Unknown。
【问题讨论】:
标签: python type-hinting mypy python-typing