← Back to index

directives_reveal_type.py

True Positive
False Positive
False Negative
Optional (detected)
Warning or Info
TP: 2
FP: 0
FN: 0
Optional: 0 / 0
1"""
2Tests the typing.reveal_type function.
3"""
4
5# Specification: https://typing.readthedocs.io/en/latest/spec/directives.html#reveal-type
6
7from typing import Any, reveal_type
8
9# > When a static type checker encounters a call to this function, it should
10# > emit a diagnostic with the type of the argument.
13def func1(a: int | str, b: list[int], c: Any, d: "ForwardReference"):
14 reveal_type(a) # Revealed type is "int | str"
[revealed-type] Revealed type: `int | str`
15 reveal_type(b) # Revealed type is "list[int]"
[revealed-type] Revealed type: `list[int]`
16 reveal_type(c) # Revealed type is "Any"
[revealed-type] Revealed type: `Any`
17 reveal_type(d) # Revealed type is "ForwardReference"
[revealed-type] Revealed type: `ForwardReference`
19 reveal_type() # E: not enough arguments
[missing-argument] No argument provided for required parameter `obj` of function `reveal_type`
20 reveal_type(a, a) # E: Too many arguments
[too-many-positional-arguments] Too many positional arguments to function `reveal_type`: expected 1, got 2
23class ForwardReference:
24 pass