-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Description
Bug Report
I understand that according to the current documentation and implementation, # type: ignore might be designed to work on a physical line. However, this leads to counterintuitive results.The behavior of # type: ignore[code] comments is inconsistent when applied to a multi-line logical statement (a single logical line spread across multiple physical lines due to parentheses). The outcome of the type check depends on the physical formatting of the code, even though the semantic meaning is identical.
To Reproduce
https://mypy-play.net/?mypy=latest&python=3.12&gist=f7e411039bf2f5ec0d4062a08fe23f17&flags=strict
def untyped(x):# type: ignore[no-untyped-def]
return x
result_a = untyped(untyped(42)) # type: ignore[no-untyped-call]https://mypy-play.net/?mypy=latest&python=3.12&gist=f81313be96f015a58d3aac52f0dfcfb9&flags=strict
def untyped(x):# type: ignore[no-untyped-def]
return x
result_b = untyped(
untyped(42) # type: ignore[no-untyped-call]
)https://mypy-play.net/?mypy=latest&python=3.12&gist=ba8cfebd99634a80de0c3cb00c35b550&flags=strict
def untyped(x):# type: ignore[no-untyped-def]
return x
result_c = untyped(
untyped(42)
) # type: ignore[no-untyped-call]Expected Behavior
a b c all success
Actual Behavior
a c success
b: error: Call to untyped function "untyped" in typed context [no-untyped-call]
Found 1 error in 1 file (checked 1 source file)
Your Environment
- Mypy version used:1.19.1
- Mypy command-line flags:strict
- Mypy configuration options from
mypy.ini(and other config files): - Python version used:3.12