-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Enforce Type Hints #1282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
You can get halfway there with the `--disallow-untyped-calls` flag.
|
Ah, I see that is in the git version, not the latest release. This is great, I'd like to see also something like Thanks for the response @gvanrossum! |
Thanks @ddfisher and @gvanrossum! |
Is there any way to strictly enforce type hints in the current version? I'd like to enforce static typing also for trivial expression like |
There is no way to require variables to be annotated if the type can be inferred by mypy, if I understood correctly that this is what you'd like to do. |
I see. Thanks for the quick reply @JukkaL! |
Would it be possible to force required annotations on variables even if mypy can infer a type? I understand why it isn't currently there but it would be handy for certain situations. EG one I've just encountered; async method: async def __category_setup(self, config_item: list[str]) -> bool: call to the above method I had in my code: enabled = self.__category_setup(path) The above code is incorrect as the method should be awaited, mypy doesn't raise any errors as it infers the variable type as Coroutine. However, if I'd typed the enabled variable as bool, mypy would've raised typing error prompting me to add in the await flag. enabled: bool = await self.__category_setup(path) Having the ability to identify all variables without type annotations via mypy would be the best way around this imo. |
I would love an option on the command line to force the use of type hints so that all code is statically typed.
Is this possible or easy to accomplish with mypy?
The text was updated successfully, but these errors were encountered: