Use either the typing.TextIO or typing.BinaryIO types, for files opened in text mode or binary mode respectively.
From the docs:
class
typing.IOWrapper namespace for I/O stream types.
This defines the generic type
IO[AnyStr]and aliasesTextIOandBinaryIOfor respectivelyIO[str]andIO[bytes]. These representing the types of I/O streams such as returned byopen().