Skip to content

Commit b67d49e

Browse files
committed
Document some exceptions expected on edge cases of fs.base.FS methods
1 parent abb8c5d commit b67d49e

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

fs/base.py

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,16 @@ def getinfo(self, path, namespaces=None):
152152
153153
Arguments:
154154
path (str): A path to a resource on the filesystem.
155-
namespaces (list, optional): Info namespaces to query
156-
(defaults to *[basic]*).
155+
namespaces (list, optional): Info namespaces to query. The
156+
`"basic"` namespace is alway included in the returned
157+
info, whatever the value of `namespaces` may be.
157158
158159
Returns:
159160
~fs.info.Info: resource information object.
160161
162+
Raises:
163+
fs.errors.ResourceNotFound: If ``path`` does not exist.
164+
161165
For more information regarding resource information, see :ref:`info`.
162166
163167
"""
@@ -235,10 +239,12 @@ def openbin(
235239
io.IOBase: a *file-like* object.
236240
237241
Raises:
238-
fs.errors.FileExpected: If the path is not a file.
239-
fs.errors.FileExists: If the file exists, and *exclusive mode*
240-
is specified (``x`` in the mode).
241-
fs.errors.ResourceNotFound: If the path does not exist.
242+
fs.errors.FileExpected: If ``path`` exists and is not a file.
243+
fs.errors.FileExists: If the ``path`` exists, and
244+
*exclusive mode* is specified (``x`` in the mode).
245+
fs.errors.ResourceNotFound: If ``path`` does not exist and
246+
``mode`` does not imply creating the file, or if any
247+
ancestor of ``path`` does not exist.
242248
243249
"""
244250

@@ -402,6 +408,7 @@ def copy(self, src_path, dst_path, overwrite=False):
402408
and ``overwrite`` is `False`.
403409
fs.errors.ResourceNotFound: If a parent directory of
404410
``dst_path`` does not exist.
411+
fs.errors.FileExpected: If ``src_path`` is not a file.
405412
406413
"""
407414
with self._lock:
@@ -587,6 +594,7 @@ def readbytes(self, path):
587594
bytes: the file contents.
588595
589596
Raises:
597+
fs.errors.FileExpected: if ``path`` exists but is not a file.
590598
fs.errors.ResourceNotFound: if ``path`` does not exist.
591599
592600
"""
@@ -603,6 +611,10 @@ def download(self, path, file, chunk_size=None, **options):
603611
This may be more efficient that opening and copying files
604612
manually if the filesystem supplies an optimized method.
605613
614+
Note that the file object ``file`` will *not* be closed by this
615+
method. Take care to close it after this method completes
616+
(ideally with a context manager).
617+
606618
Arguments:
607619
path (str): Path to a resource.
608620
file (file-like): A file-like object open for writing in
@@ -613,14 +625,13 @@ def download(self, path, file, chunk_size=None, **options):
613625
**options: Implementation specific options required to open
614626
the source file.
615627
616-
Note that the file object ``file`` will *not* be closed by this
617-
method. Take care to close it after this method completes
618-
(ideally with a context manager).
619-
620628
Example:
621629
>>> with open('starwars.mov', 'wb') as write_file:
622630
... my_fs.download('/Videos/starwars.mov', write_file)
623631
632+
Raises:
633+
fs.errors.ResourceNotFound: if ``path`` does not exist.
634+
624635
"""
625636
with self._lock:
626637
with self.openbin(path, **options) as read_file:
@@ -698,7 +709,7 @@ def getmeta(self, namespace="standard"):
698709
network.
699710
read_only `True` if this filesystem is read only.
700711
supports_rename `True` if this filesystem supports an
701-
`os.rename` operation.
712+
`os.rename` operation (or equivalent).
702713
=================== ============================================
703714
704715
Most builtin filesystems will provide all these keys, and third-
@@ -726,6 +737,9 @@ def getsize(self, path):
726737
Returns:
727738
int: the *size* of the resource.
728739
740+
Raises:
741+
fs.errors.ResourceNotFound: if ``path`` does not exist.
742+
729743
The *size* of a file is the total number of readable bytes,
730744
which may not reflect the exact number of bytes of reserved
731745
disk space (or other storage medium).
@@ -1018,6 +1032,8 @@ def movedir(self, src_path, dst_path, create=False):
10181032
Raises:
10191033
fs.errors.ResourceNotFound: if ``dst_path`` does not exist,
10201034
and ``create`` is `False`.
1035+
fs.errors.DirectoryExpected: if ``src_path`` or one of its
1036+
ancestors is not a directory.
10211037
10221038
"""
10231039
with self._lock:
@@ -1617,13 +1633,16 @@ def hash(self, path, name):
16171633
Arguments:
16181634
path(str): A path on the filesystem.
16191635
name(str):
1620-
One of the algorithms supported by the hashlib module, e.g. `"md5"`
1636+
One of the algorithms supported by the `hashlib` module,
1637+
e.g. `"md5"` or `"sha256"`.
16211638
16221639
Returns:
16231640
str: The hex digest of the hash.
16241641
16251642
Raises:
16261643
fs.errors.UnsupportedHash: If the requested hash is not supported.
1644+
fs.errors.ResourceNotFound: If ``path`` does not exist.
1645+
fs.errors.FileExpected: If ``path`` exists but is not a file.
16271646
16281647
"""
16291648
self.validatepath(path)

fs/ftpfs.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,6 @@ class FTPFS(FS):
358358
FTPS, or FTP Secure. TLS will be enabled when using the ftps:// protocol,
359359
or when setting the `tls` argument to True in the constructor.
360360
361-
362361
Examples:
363362
Create with the constructor::
364363

0 commit comments

Comments
 (0)