小编Min*_*Po1的帖子

~<type> 有什么作用?

在编写代码时,我遇到过表达类型的 linter ~<type>(其中<type>类型不是<type>文学的)。一个例子是self

class A:
    def foo(self):
        reveal_type(self) # reveals "~A"
Run Code Online (Sandbox Code Playgroud)

我认为这意味着“A或”的子类A;但是,我在网上找不到任何有关它的信息。

另外,您不能在代码中使用以下语法:

a: ~A # raises an exception: TypeError: bad operand type for unary ~: 'type'
Run Code Online (Sandbox Code Playgroud)

如果a会被揭露的话那就是了Unknown

python type-hinting mypy python-typing

3
推荐指数
1
解决办法
261
查看次数

标签 统计

mypy ×1

python ×1

python-typing ×1

type-hinting ×1