← Back to index

directives_no_type_check.py

True Positive
False Positive
False Negative
Optional (detected)
Warning or Info
TP: 1
FP: 0
FN: 0
Optional: 2 / 4
1"""
2Tests the typing.no_type_check decorator.
3"""
4
5# Specification: https://typing.readthedocs.io/en/latest/spec/directives.html#no-type-check
6# "E?" is used below because support is optional.
7
8from typing import no_type_check
9
10# > The behavior for the ``no_type_check`` decorator when applied to a class is
11# > left undefined by the typing spec at this time.
13@no_type_check
14class ClassA:
15 x: int = "" # E?: No error should be reported
[invalid-assignment] Object of type `Literal[""]` is not assignable to `int`
18# > If a type checker supports the ``no_type_check`` decorator for functions, it
19# > should suppress all type errors for the ``def`` statement and its body including
20# > any nested functions or classes. It should also ignore all parameter
21# > and return type annotations and treat the function as if it were unannotated.
23@no_type_check
24def func1(a: int, b: str) -> None:
25 c = a + b # E?: No error should be reported
26 return 1 # E?: No error should be reported
29func1(b"invalid", b"arguments") # E?: No error should be reported
[invalid-argument-type] Argument to function `func1` is incorrect: Expected `int`, found `Literal[b"invalid"]` [invalid-argument-type] Argument to function `func1` is incorrect: Expected `str`, found `Literal[b"arguments"]`
30# This should still be an error because type checkers should ignore
31# annotations, but still check the argument count.
32func1() # E: incorrect arguments for parameters
[missing-argument] No arguments provided for required parameters `a`, `b` of function `func1`