Skip to content

Commit 7fe529b

Browse files
committed
Document more of the expected exceptions in fs.base.FS interface
1 parent 53f6e14 commit 7fe529b

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

fs/base.py

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,8 @@ def copydir(self, src_path, dst_path, create=False):
431431
Raises:
432432
fs.errors.ResourceNotFound: If the ``dst_path``
433433
does not exist, and ``create`` is not `True`.
434+
fs.errors.DirectoryExpected: If ``src_path`` is not a
435+
directory.
434436
435437
"""
436438
with self._lock:
@@ -474,6 +476,9 @@ def desc(self, path):
474476
Returns:
475477
str: a short description of the path.
476478
479+
Raises:
480+
fs.errors.ResourceNotFound: If ``path`` does not exist.
481+
477482
"""
478483
if not self.exists(path):
479484
raise errors.ResourceNotFound(path)
@@ -828,6 +833,9 @@ def gettype(self, path):
828833
Returns:
829834
~fs.enums.ResourceType: the type of the resource.
830835
836+
Raises:
837+
fs.errors.ResourceNotFound: if ``path`` does not exist.
838+
831839
A type of a resource is an integer that identifies the what
832840
the resource references. The standard type integers may be one
833841
of the values in the `~fs.enums.ResourceType` enumerations.
@@ -1201,8 +1209,8 @@ def opendir(
12011209
~fs.subfs.SubFS: A filesystem representing a sub-directory.
12021210
12031211
Raises:
1204-
fs.errors.DirectoryExpected: If ``dst_path`` does not
1205-
exist or is not a directory.
1212+
fs.errors.ResourceNotFound: If ``path`` does not exist.
1213+
fs.errors.DirectoryExpected: If ``path`` is not a directory.
12061214
12071215
"""
12081216
from .subfs import SubFS
@@ -1223,6 +1231,10 @@ def removetree(self, dir_path):
12231231
Arguments:
12241232
dir_path (str): Path to a directory on the filesystem.
12251233
1234+
Raises:
1235+
fs.errors.ResourceNotFound: If ``dir_path`` does not exist.
1236+
fs.errors.DirectoryExpected: If ``dir_path`` is not a directory.
1237+
12261238
Caution:
12271239
A filesystem should never delete its root folder, so
12281240
``FS.removetree("/")`` has different semantics: the
@@ -1497,11 +1509,10 @@ def validatepath(self, path):
14971509
str: A normalized, absolute path.
14981510
14991511
Raises:
1512+
fs.errors.InvalidPath: If the path is invalid.
1513+
fs.errors.FilesystemClosed: if the filesystem is closed.
15001514
fs.errors.InvalidCharsInPath: If the path contains
15011515
invalid characters.
1502-
fs.errors.InvalidPath: If the path is invalid.
1503-
fs.errors.FilesystemClosed: if the filesystem
1504-
is closed.
15051516
15061517
"""
15071518
self.check()
@@ -1597,18 +1608,23 @@ def match(self, patterns, name):
15971608
# type: (Optional[Iterable[Text]], Text) -> bool
15981609
"""Check if a name matches any of a list of wildcards.
15991610
1611+
If a filesystem is case *insensitive* (such as Windows) then
1612+
this method will perform a case insensitive match (i.e. ``*.py``
1613+
will match the same names as ``*.PY``). Otherwise the match will
1614+
be case sensitive (``*.py`` and ``*.PY`` will match different
1615+
names).
1616+
16001617
Arguments:
1601-
patterns (list): A list of patterns, e.g. ``['*.py']``
1618+
patterns (list, optional): A list of patterns, e.g.
1619+
``['*.py']``, or `None` to match everything.
16021620
name (str): A file or directory name (not a path)
16031621
16041622
Returns:
16051623
bool: `True` if ``name`` matches any of the patterns.
16061624
1607-
If a filesystem is case *insensitive* (such as Windows) then
1608-
this method will perform a case insensitive match (i.e. ``*.py``
1609-
will match the same names as ``*.PY``). Otherwise the match will
1610-
be case sensitive (``*.py`` and ``*.PY`` will match different
1611-
names).
1625+
Raises:
1626+
TypeError: If ``patterns`` is a single string instead of
1627+
a list (or `None`).
16121628
16131629
Example:
16141630
>>> my_fs.match(['*.py'], '__init__.py')

0 commit comments

Comments
 (0)