I have started to use type hinting today. After reading documentation about type hinting I tried to write some dumb examples to check how it works and was stuck at something as simple as this.
a: int = 7.33
I don't get any warning or error. Everything is working like I wasn't using type hinting. I was expecting a warning saying that a float can't be assigned to an int var.
I have tried other things like:
def sum_two_numbers(a:int , b:int)->int:
return a+b
def main() -> None:
asd = sum_two_numbers(2, 5.4)
and as expected I get a warning in the 5.4 number. Pycharm warns that I'm passing a float were an int should be.
So, what is happening here?
Edited: I Have tried mypy and it correctly detects the previous problem I stated. Is there anyway to make pycharm detect it too?
Cheers.
PyCharm doesn't check types for variable assignments, unfortunately. Please vote for PY-24832.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With