Type "any" conflicts with function "any" in builtins.pyi

Viewed 32

When I write a: any, Pylance says:

Expected class type but received \"(__iterable: Iterable[object], /) -> bool\

because builtins.pyi has def any(__iterable: Iterable[object]) -> bool: ....

Any workarounds other than from typing import Any?

I'm using Python 3.10.6.

1 Answers

As @SUTerliakov describes:

Any from typing is absolutely unrelated to any builtin: the former is a type hint, while the latter is a function. Other types are different: Dict was introduced as a type hint for dict builtin type, same with list and set. Type vs type are not 100% compatible too, but it was decided to allow type[something] as a type hint. Any is not the case.

So I need to use Any in my case.

Related