Unnecessary/redundant type hints #7758
Replies: 2 comments 2 replies
-
There's really no such thing as an "unnecessary or redundant type hint". The term "type hint" is a bit misleading, so I try to avoid using it. Type annotations are not really "hints"; they're declarations. When you add a type annotation to a variable, you're declaring the upper bound of the type that the variable can be assigned. Without a type declaration, the variable is bound only by i = 1
i = "" # No type violation
i = [1, 2, 3] # No type violation
j: int = 1
j = "" # Type violation
j = [1, 2, 3] # Type violation So, you can choose to use type declarations if you want to enforce the type of a variable. There are reasons to do this some times. To better understand the concept of type declarations, refer to this documentation. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the information, that all makes sense! |
Beta Was this translation helpful? Give feedback.
-
Is it possible to add some kind of setting checking for unnecessary/redundant type hints? Close in behavior to the existing
reportUnnecessaryTypeIgnoreComment
.Example:
Beta Was this translation helpful? Give feedback.
All reactions