-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial implementation of inline configuration
Implements line configuration using '# mypy: ' comments, following the blueprint I proposed in #2938. It currently finds them just using a regex which means it is possible to pick up a directive spuriously in a string literal or something but honestly I am just not worried about that in practice. Examples of what it looks like in the tests. Fixes #2938. Thoughts?
- Loading branch information
Showing
6 changed files
with
223 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
-- Checks for 'mypy: option' directives inside files | ||
|
||
[case testInlineSimple1] | ||
# mypy: disallow-any-generics, no-warn-no-return | ||
|
||
from typing import List | ||
def foo() -> List: # E: Missing type parameters for generic type | ||
20 | ||
|
||
[builtins fixtures/list.pyi] | ||
|
||
[case testInlineSimple2] | ||
# mypy: disallow-any-generics | ||
# mypy: no-warn-no-return | ||
|
||
from typing import List | ||
def foo() -> List: # E: Missing type parameters for generic type | ||
20 | ||
|
||
[builtins fixtures/list.pyi] | ||
|
||
[case testInlineSimple3] | ||
# mypy: disallow-any-generics=true, warn-no-return=0 | ||
|
||
from typing import List | ||
def foo() -> List: # E: Missing type parameters for generic type | ||
20 | ||
|
||
[builtins fixtures/list.pyi] | ||
|
||
[case testInlineList] | ||
# mypy: disallow-any-generics, always-false=FOO,BAR | ||
|
||
from typing import List | ||
|
||
def foo(FOO: bool, BAR: bool) -> List: # E: Missing type parameters for generic type | ||
if FOO or BAR: | ||
1+'lol' | ||
return [] | ||
|
||
[builtins fixtures/list.pyi] | ||
|
||
[case testInlineIncremental1] | ||
import a | ||
[file a.py] | ||
# mypy: disallow-any-generics, no-warn-no-return | ||
|
||
from typing import List | ||
def foo() -> List: | ||
20 | ||
|
||
[file a.py.2] | ||
# mypy: no-warn-no-return | ||
|
||
from typing import List | ||
def foo() -> List: | ||
20 | ||
|
||
[file a.py.3] | ||
from typing import List | ||
def foo() -> List: | ||
20 | ||
[out] | ||
tmp/a.py:4: error: Missing type parameters for generic type | ||
[out2] | ||
[out3] | ||
tmp/a.py:2: error: Missing return statement | ||
|
||
[builtins fixtures/list.pyi] | ||
|
||
[case testInlineIncremental2] | ||
# flags2: --disallow-any-generics | ||
import a | ||
[file a.py] | ||
# mypy: no-warn-no-return | ||
|
||
from typing import List | ||
def foo() -> List: | ||
20 | ||
|
||
[file b.py.2] | ||
# no changes to a.py, but flag change should cause recheck | ||
|
||
[out] | ||
[out2] | ||
tmp/a.py:4: error: Missing type parameters for generic type | ||
|
||
[builtins fixtures/list.pyi] | ||
|
||
[case testInlineIncremental3] | ||
import a, b | ||
[file a.py] | ||
# mypy: no-warn-no-return | ||
|
||
def foo() -> int: | ||
20 | ||
|
||
[file b.py] | ||
[file b.py.2] | ||
# no changes to a.py and we want to make sure it isn't rechecked | ||
[out] | ||
[out2] | ||
[rechecked b] | ||
|
||
[case testInlineError1] | ||
# mypy: invalid-whatever | ||
[out] | ||
main: error: Unrecognized option: invalid_whatever = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters