'How to type-annotate a file-like object in Python 3.8+
Previously typing.IO, typing.TextIO, and typing.BinaryIO were available to annotate file-like objects, e.g. those returned by open(). However, after Python 3.8 they seem to be deprecated, and will be removed in Python 3.12. Unlike many of the other deprecations like typing.List[T], which is replaced by list[T], these IO types have no clear migration path.
How should file-like object types be annotated in modern Python, going forward?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
