You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
reportAny is hard to actually enable in a codebase, because there seems to be no way to avoid the errors. Preferably, by setting reportAny: true and reportExplicitAny: false, it should make it so that all uses of Any require some explicit annotation (So as to not "accidentally" let an Any from a poorly typed library spread all over your codebase).
Here are some errors that make it difficult to use this configuration option in practice:
Can't use as return type of a function
Even though dict[Any, Any] works,
It's not possible to explicitly cast something into Any
It's not possible to destructure an Any from a tuple
It's not possible to explicitly cast to a primitive
(Using cast() works, but that is unsafe - explicit casting will legitimately try to cast it or throw an error if it cant.)
But, maybe this is barking up the wrong tree, maybe the correct way to get the desired behavior is just to make it so that imports from external libraries always presume Unknown rather than Any, even if the library explicitly says the return type is Any.
The text was updated successfully, but these errors were encountered:
float isn't really a "cast", or a "primitive", it's a call that performs a conversation based on an interface, I don't think it should be special cased
1 & 2 - i agree those should probably be reported as reportExplicitAny instead of reportAny.
3 - i think this one is fine as is, since it's not an explicit usage of Any therefore i would consider it implicit. it's more likely that the Any is not being used intentionally
4 - i agree with @KotlinIsland. while it's not ideal it still technically is an implicit Any, and changing the behavior would probably involve special casing those builtin constructors which i think would just make the rule's behavior more confusing
Description
reportAny is hard to actually enable in a codebase, because there seems to be no way to avoid the errors. Preferably, by setting
reportAny: true
andreportExplicitAny: false
, it should make it so that all uses of Any require some explicit annotation (So as to not "accidentally" let anAny
from a poorly typed library spread all over your codebase).Here are some errors that make it difficult to use this configuration option in practice:
Can't use as return type of a function


Even though
dict[Any, Any]
works,It's not possible to explicitly cast something into Any

It's not possible to destructure an Any from a tuple

It's not possible to explicitly cast to a primitive

(Using
cast()
works, but that is unsafe - explicit casting will legitimately try to cast it or throw an error if it cant.)But, maybe this is barking up the wrong tree, maybe the correct way to get the desired behavior is just to make it so that imports from external libraries always presume
Unknown
rather thanAny
, even if the library explicitly says the return type isAny
.The text was updated successfully, but these errors were encountered: