-
Hello, from typing import Any
def accept_any(foo: Any) -> None:
print(type(foo)) # Should be OK, but it's not OK
def accept_str(bar: str) -> None:
print(type(bar))
def call_the_functions_above(foo: Any) -> None:
accept_any(foo) # Should be OK, and it's OK
accept_str(foo) # Should not be OK, but it's OK |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
If you want your code to be fully type checked, you should avoid using |
Beta Was this translation helpful? Give feedback.
Any
has a very specific meaning in the Python typing spec, and pyright conforms to the spec. For more details, refer to this section of the spec.If you want your code to be fully type checked, you should avoid using
Any
wherever possible. When you useAny
, you're effectively telling the type checker "I don't know what type this is, so assume that it's any type that could possibly satisfy type checking constraints".