basedmypy icon indicating copy to clipboard operation
basedmypy copied to clipboard

A flag to treat third-party `Any` as `object`/`Untyped`

Open DetachHead opened this issue 3 years ago • 2 comments

The flag will default to false and will be mandatory for all targets.

Eg: thirdparty.pyi

def foo(a: list[Any]) -> Any: ...

my.py

from thirdparty import foo
reveal_type(foo)  # def (a: list[object]) -> object

a: int = foo([1])  # error: expression has type "object" variable has type "int"

I don't see any value in converting it to Untyped or showing an error that a parameter is typed as Any, how would you be able to do anything to fix it?

DetachHead avatar Jan 12 '22 05:01 DetachHead

Any expression errors are so common, this would help a lot.

KotlinIsland avatar Mar 25 '22 00:03 KotlinIsland

@DetachHead After thinking about these kind of issues a bit I think this might not be the best resolution, but if you can provide some examples where this is based that would help me out a bit.

What about something more like:

third_party.foo(1)  # call to function with `Any`
third_party.bar = 1  # assignment to attribute with `Any`
some_list = third_party.get_list()  # error, return type contains any
some_list = cast(list[int], third_party.get_list())  # that's okay
some_list: list[int] = third_party.get_list()  # that's okay

KotlinIsland avatar Apr 13 '22 03:04 KotlinIsland