Operations on Any values

You can do anything using a value with type Any, and type checkerdoes not complain:

  1. def f(x: Any) -> int:
  2. # All of these are valid!
  3. x.foobar(1, y=2)
  4. print(x[3] + 'f')
  5. if x:
  6. x.z = x(2)
  7. open(x).read()
  8. return x

Values derived from an Any value also often have the type Anyimplicitly, 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:

  1. def f(x: Any) -> None:
  2. y = x.foo() # y has type Any
  3. y.bar() # Okay as well!

Any types may propagate through your program, making type checkingless effective, unless you are careful.