-
From what I understand, from typing import Any, reveal_type
# Just some setup, not that relevant
def helper(*args):
"""Helper function to return a tuple[Unknown, ...] type."""
return args
unknown = helper()[0] # I know this would be a runtime error, not relevant to the question though
reveal_type(unknown) # Unknown
any: Any = "hi"
string: str = "hello"
# Relevant
x: int = any
reveal_type(x) # int
y: int = string # pyright: ignore[reportAssignmentType]
reveal_type(y) # int (not str | int)
z: int = unknown
reveal_type(z) # Unknown | int (why?) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
You're correct that In this case, I've intentionally deviated from this principle because of the way the If you're not interested in receiving diagnostics for |
Beta Was this translation helpful? Give feedback.
A
# pyright: ignore
comment does not affect type evaluation behavior; it simply suppresses any diagnostics on that line.The
reportUnknown...
checks report the use of anUnknown
. IfUnknown
was not retained, you would see no strict-mode diagnostic in this code sequence despite the fact that it represents a typing hole.