Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type hinting not always working in pycharm 2018.1?

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.

like image 930
Notbad Avatar asked Oct 16 '22 20:10

Notbad


1 Answers

PyCharm doesn't check types for variable assignments, unfortunately. Please vote for PY-24832.

like image 86
Pavel Karateev Avatar answered Nov 15 '22 06:11

Pavel Karateev