You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, the return type of CloudPath.open() is always IO[Any]. This differs from pathlib.Path.open(), which returns more specific types like TextIOWrapper, FileIO, BufferedRandom, BufferedWriter, BufferedReader, BinaryIO, or IO[Any] depending on arguments such as mode, buffering, and encoding. The more specific return types are useful for catching typing issues where a library expects a file handle in binary or text mode, specified as IO[bytes] or IO[str], respectively. With the current behavior, passing a file handle returned by CloudPath.open() often requires using typing.cast() or # type: ignore.
Here’s an example illustrating the current behavior compared to pathlib.Path.open():
Currently, the return type of
CloudPath.open()
is alwaysIO[Any]
. This differs frompathlib.Path.open()
, which returns more specific types likeTextIOWrapper
,FileIO
,BufferedRandom
,BufferedWriter
,BufferedReader
,BinaryIO
, orIO[Any]
depending on arguments such asmode
,buffering
, andencoding
. The more specific return types are useful for catching typing issues where a library expects a file handle in binary or text mode, specified asIO[bytes]
orIO[str]
, respectively. With the current behavior, passing a file handle returned byCloudPath.open()
often requires usingtyping.cast()
or# type: ignore
.Here’s an example illustrating the current behavior compared to
pathlib.Path.open()
:The text was updated successfully, but these errors were encountered: