Skip to content

Commit 3ea23b5

Browse files
committed
Fix type annotation and docs of temp_fs parameter of archive FS
1 parent 3404061 commit 3ea23b5

2 files changed

Lines changed: 21 additions & 19 deletions

File tree

fs/tarfs.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ def _get_member_info(member, encoding):
6666
class TarFS(WrapFS):
6767
"""Read and write tar files.
6868
69-
There are two ways to open a TarFS for the use cases of reading
69+
There are two ways to open a `TarFS` for the use cases of reading
7070
a tar file, and creating a new one.
7171
72-
If you open the TarFS with ``write`` set to `False` (the
72+
If you open the `TarFS` with ``write`` set to `False` (the
7373
default), then the filesystem will be a read only filesystem which
7474
maps to the files and directories within the tar file. Files are
7575
decompressed on the fly when you open them.
@@ -79,9 +79,9 @@ class TarFS(WrapFS):
7979
with TarFS('foo.tar.gz') as tar_fs:
8080
readme = tar_fs.readtext('readme.txt')
8181
82-
If you open the TarFS with ``write`` set to `True`, then the TarFS
82+
If you open the TarFS with ``write`` set to `True`, then the `TarFS`
8383
will be a empty temporary filesystem. Any files / directories you
84-
create in the TarFS will be written in to a tar file when the TarFS
84+
create in the `TarFS` will be written in to a tar file when the `TarFS`
8585
is closed. The compression is set from the new file name but may be
8686
set manually with the ``compression`` argument.
8787
@@ -100,8 +100,9 @@ class TarFS(WrapFS):
100100
use default (`False`) to read an existing tar file.
101101
compression (str, optional): Compression to use (one of the formats
102102
supported by `tarfile`: ``xz``, ``gz``, ``bz2``, or `None`).
103-
temp_fs (str): An FS URL for the temporary filesystem
104-
used to store data prior to tarring.
103+
temp_fs (str): An FS URL or an FS instance to use to store
104+
data prior to tarring. Defaults to creating a new
105+
`~fs.tempfs.TempFS`.
105106
106107
"""
107108

@@ -118,7 +119,7 @@ def __new__( # type: ignore
118119
write=False, # type: bool
119120
compression=None, # type: Optional[Text]
120121
encoding="utf-8", # type: Text
121-
temp_fs="temp://__tartemp__", # type: Text
122+
temp_fs="temp://__tartemp__", # type: Union[Text, FS]
122123
):
123124
# type: (...) -> FS
124125
if isinstance(file, (six.text_type, six.binary_type)):
@@ -164,7 +165,7 @@ def __init__(
164165
file, # type: Union[Text, BinaryIO]
165166
compression=None, # type: Optional[Text]
166167
encoding="utf-8", # type: Text
167-
temp_fs="temp://__tartemp__", # type: Text
168+
temp_fs="temp://__tartemp__", # type: Union[Text, FS]
168169
): # noqa: D107
169170
# type: (...) -> None
170171
self._file = file # type: Union[Text, BinaryIO]

fs/zipfs.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,11 @@ def tell(self):
124124
class ZipFS(WrapFS):
125125
"""Read and write zip files.
126126
127-
There are two ways to open a ZipFS for the use cases of reading
127+
There are two ways to open a `ZipFS` for the use cases of reading
128128
a zip file, and creating a new one.
129129
130-
If you open the ZipFS with ``write`` set to `False` (the default)
131-
then the filesystem will be a read only filesystem which maps to
130+
If you open the `ZipFS` with ``write`` set to `False` (the default)
131+
then the filesystem will be a read-only filesystem which maps to
132132
the files and directories within the zip file. Files are
133133
decompressed on the fly when you open them.
134134
@@ -137,12 +137,12 @@ class ZipFS(WrapFS):
137137
with ZipFS('foo.zip') as zip_fs:
138138
readme = zip_fs.readtext('readme.txt')
139139
140-
If you open the ZipFS with ``write`` set to `True`, then the ZipFS
141-
will be a empty temporary filesystem. Any files / directories you
142-
create in the ZipFS will be written in to a zip file when the ZipFS
140+
If you open the `ZipFS` with ``write`` set to `True`, then the `ZipFS`
141+
will be an empty temporary filesystem. Any files / directories you
142+
create in the `ZipFS` will be written in to a zip file when the `ZipFS`
143143
is closed.
144144
145-
Here's how you might write a new zip file containing a readme.txt
145+
Here's how you might write a new zip file containing a ``readme.txt``
146146
file::
147147
148148
with ZipFS('foo.zip', write=True) as new_zip:
@@ -158,8 +158,9 @@ class ZipFS(WrapFS):
158158
(default) to read an existing zip file.
159159
compression (int): Compression to use (one of the constants
160160
defined in the `zipfile` module in the stdlib).
161-
temp_fs (str): An FS URL for the temporary filesystem used to
162-
store data prior to zipping.
161+
temp_fs (str or FS): An FS URL or an FS instance to use to
162+
store data prior to zipping. Defaults to creating a new
163+
`~fs.tempfs.TempFS`.
163164
164165
"""
165166

@@ -170,7 +171,7 @@ def __new__( # type: ignore
170171
write=False, # type: bool
171172
compression=zipfile.ZIP_DEFLATED, # type: int
172173
encoding="utf-8", # type: Text
173-
temp_fs="temp://__ziptemp__", # type: Text
174+
temp_fs="temp://__ziptemp__", # type: Union[Text, FS]
174175
):
175176
# type: (...) -> FS
176177
# This magic returns a different class instance based on the
@@ -205,7 +206,7 @@ def __init__(
205206
file, # type: Union[Text, BinaryIO]
206207
compression=zipfile.ZIP_DEFLATED, # type: int
207208
encoding="utf-8", # type: Text
208-
temp_fs="temp://__ziptemp__", # type: Text
209+
temp_fs="temp://__ziptemp__", # type: Union[Text, FS]
209210
): # noqa: D107
210211
# type: (...) -> None
211212
self._file = file

0 commit comments

Comments
 (0)