Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mypy not detecting a basic type error

With python 3.5.1. and a current installation of mypy using git, mypy flags error 1 & 2, but it does not report 3

What am I doing wrong, or is this a bug, or is this a known problem?

import typing

def test_ordered_dict(od: typing.Dict[str,int]) -> typing.Dict[str,int]:
    return 1   #type error 1

a = test_ordered_dict(1)   #type error 2

def test_me():
    a = test_ordered_dict(1)  # type error 3 is not reported
like image 224
Tim Richardson Avatar asked Jan 13 '16 02:01

Tim Richardson


1 Answers

My understanding from the docs is that mypy will only check a thing (module, function, whatever) if it's indicated to it that it should check it (by importing typing at module level or by annotating a function).

So 1 is checked because it's in a function which is typed, 2 is checked as the import typing indicates that your module is typed and it's at module scope but 3 is in the scope of an untyped function so it's ignored.

like image 149
Macha Avatar answered Oct 15 '22 22:10

Macha