I've read some other answers, and they seem contradictory to what happens IRL.
Try the following:
from typing import IO
from pathlib import Path
example_path = Path(r"D:\Example.txt")
with example_path.open("r") as f:
print(isinstance(f, IO))
with open(example_path) as f:
print(isinstance(f, IO))
It will print:
False
False
That's baffling, because according to documentation, it seems to me that one of the very purposes of typing.IO is for type-checking an object for IO type, and this would include the use of isinstance(). Why doesn't it work? Doesn't that defeat the very purpose? What am I missing here?