gpt4 book ai didi

python - ~ 是做什么的?

转载 作者:行者123 更新时间:2023-12-02 01:57:15 24 4
gpt4 key购买 nike

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

class A:
def foo(self):
reveal_type(self) # reveals "~A"

我假设这意味着“AA 的子类”;但是,我无法在网上找到有关它的任何信息。

此外,您不能在代码中使用此语法:

a: ~A # raises an exception: TypeError: bad operand type for unary ~: 'type'

如果a本来会被揭露的 Unknown .

最佳答案

查看 source code , TypeVars 打印 (repr) 前导“+”如果它们是协变的,“-”如果是逆变的,“~”如果不变(既不是协变也不是逆变)。

关于python - ~<type> 是做什么的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69501252/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com