简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM