Skip to content

Commit a57b857

Browse files
committed
Improve Info.is_writable to document the _write key of every namespace
1 parent 6abc786 commit a57b857

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

fs/info.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Info(object):
4141
raw_info (dict): A dict containing resource info.
4242
to_datetime (callable): A callable that converts an
4343
epoch time to a datetime object. The default uses
44-
:func:`~fs.time.epoch_to_datetime`.
44+
`~fs.time.epoch_to_datetime`.
4545
4646
"""
4747

@@ -132,7 +132,8 @@ def is_writeable(self, namespace, key):
132132
# type: (Text, Text) -> bool
133133
"""Check if a given key in a namespace is writable.
134134
135-
Uses `~fs.base.FS.setinfo`.
135+
When creating an `Info` object, you can add a ``_write`` key to
136+
each raw namespace that lists which keys are writable or not.
136137
137138
Arguments:
138139
namespace (str): A namespace identifier.
@@ -141,6 +142,24 @@ def is_writeable(self, namespace, key):
141142
Returns:
142143
bool: `True` if the key can be modified, `False` otherwise.
143144
145+
Example:
146+
Create an `Info` object that marks only the ``modified`` key
147+
as writable in the ``details`` namespace::
148+
149+
>>> now = time.time()
150+
>>> info = Info({
151+
... "basic": {"name": "foo", "is_dir": False},
152+
... "details": {
153+
... "modified": now,
154+
... "created": now,
155+
... "_write": ["modified"],
156+
... }
157+
... })
158+
>>> info.is_writeable("details", "created")
159+
False
160+
>>> info.is_writeable("details", "modified")
161+
True
162+
144163
"""
145164
_writeable = self.get(namespace, "_write", ())
146165
return key in _writeable

0 commit comments

Comments
 (0)