TYP/DOC: Use Protocols for file-like objects in read/to_* #41610
Labels
Enhancement
IO Data
IO issues that don't fit into a more specific label
Typing
type annotations, mypy/pyright type checking
Milestone
Is your feature request related to a problem?
It is often not clear which methods a "file-like object" needs to implement to be compatible with
read/to_*
.Describe the solution you'd like
Define multiple
typing.Protocol
s to make clear which methods need to be implemented, similar to python/typeshed/issues/4212.This will probably be a bit messy: 1) many protocols and 2) most libraries expect
typing.IO
(which will lead to a few ignore/cast statements but also might make it difficult to determine the set of compatible protocols).edit:
If feasible, I would like that
pandas.io.common.get_handle
has roughly the following interface:The text was updated successfully, but these errors were encountered: