Operations on Any values
You can do anything using a value with type Any
, and type checkerdoes not complain:
- def f(x: Any) -> int:
- # All of these are valid!
- x.foobar(1, y=2)
- print(x[3] + 'f')
- if x:
- x.z = x(2)
- open(x).read()
- return x
Values derived from an Any
value also often have the type Any
implicitly, as mypy can’t infer a more precise result type. Forexample, if you get the attribute of an Any
value or call aAny
value the result is Any
:
- def f(x: Any) -> None:
- y = x.foo() # y has type Any
- y.bar() # Okay as well!
Any
types may propagate through your program, making type checkingless effective, unless you are careful.