When writing code I have encountered my linter expressing the type of ~<type> (where <type> is a type not <type> literary). An example of this is self.
class A:
def foo(self):
reveal_type(self) # reveals "~A"
I assume this means "A or a subclass of A"; however, I was unable to find any information about it online.
Also, you can't use this syntax in code:
a: ~A # raises an exception: TypeError: bad operand type for unary ~: 'type'
If a would have been revealed it would be Unknown.
Looking at the source code, TypeVars are printed (repr) with a leading "+" if they are covariant, "-" if contravariant, and "~" if invariant (neither covariant nor contravariant).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With