Skip to content

Commit 3adad8f

Browse files
committed
Improve documented types of methods that accept all of: filepaths (as text, binary or PathLike), open binary files, file descriptors on Unix
Also mark methods returning binary strings as returning `bytes` (not the Python 2 `str` type)
1 parent c1120f5 commit 3adad8f

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

ipfshttpclient/client/block.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def get(self, multihash, **kwargs):
2626
2727
Returns
2828
-------
29-
str : Value of the requested block
29+
bytes : Value of the requested block
3030
"""
3131
args = (multihash,)
3232
return self._client.request('/block/get', args, **kwargs)
@@ -43,7 +43,7 @@ def put(self, file, **kwargs):
4343
4444
Parameters
4545
----------
46-
file : io.RawIOBase
46+
file : str | bytes | os.PathLike | io.IOBase | int
4747
The data to be stored as an IPFS block
4848
4949
Returns

ipfshttpclient/client/files.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def cp(self, source, dest, **kwargs):
3939
source : str
4040
Filepath within the MFS to copy from
4141
dest : str
42-
Destination filepath with the MFS to which the file will be
42+
Destination filepath within the MFS to which the file will be
4343
copied to
4444
"""
4545
args = (source, dest)
@@ -132,7 +132,7 @@ def read(self, path, offset=0, count=None, **kwargs):
132132
133133
Returns
134134
-------
135-
str : MFS file contents
135+
bytes : MFS file contents
136136
"""
137137
opts = {"offset": offset}
138138
if count is not None:
@@ -149,7 +149,6 @@ def rm(self, path, recursive=False, **kwargs):
149149
.. code-block:: python
150150
151151
>>> client.files.rm("/bla/file")
152-
b''
153152
154153
Parameters
155154
----------
@@ -199,7 +198,7 @@ def write(self, path, file, offset=0, create=False, truncate=False, count=None,
199198
----------
200199
path : str
201200
Filepath within the MFS
202-
file : io.RawIOBase
201+
file : str | bytes | os.PathLike | io.RawIOBase | int
203202
IO stream object with data that should be written
204203
offset : int
205204
Byte offset at which to begin writing at
@@ -237,10 +236,10 @@ def add(self, files, recursive=False, pattern='**', *args, **kwargs):
237236
238237
Parameters
239238
----------
240-
files : str
239+
files : str | bytes | os.PathLike | int | io.IOBase | collections.abc.Iterable
241240
A filepath to either a file or directory
242241
recursive : bool
243-
Controls if files in subdirectories are added or not
242+
Controls whether files in subdirectories are added or not
244243
pattern : str | list
245244
Single `*glob* <https://docs.python.org/3/library/glob.html>`_
246245
pattern or list of *glob* patterns and compiled regular expressions
@@ -366,7 +365,7 @@ def cat(self, multihash, offset=0, length=-1, **kwargs):
366365
367366
Returns
368367
-------
369-
str : File contents
368+
bytes : File contents
370369
"""
371370
args = (multihash,)
372371
opts = {}

ipfshttpclient/client/object.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def append_data(self, multihash, new_data, **kwargs):
5757
----------
5858
multihash : str
5959
The hash of an ipfs object to modify
60-
new_data : io.RawIOBase
60+
new_data : str | bytes | os.PathLike | io.IOBase | int
6161
The data to append to the object's data section
6262
6363
Returns
@@ -116,7 +116,7 @@ def set_data(self, root, data, **kwargs):
116116
----------
117117
root : str
118118
IPFS hash of the object to modify
119-
data : io.RawIOBase
119+
data : str | bytes | os.PathLike | io.IOBase | int
120120
The new data to store in root
121121
122122
Returns
@@ -149,15 +149,15 @@ def data(self, multihash, **kwargs):
149149
150150
Returns
151151
-------
152-
str : Raw object data
152+
bytes : Raw object data
153153
"""
154154
args = (multihash,)
155155
return self._client.request('/object/data', args, **kwargs)
156156

157157

158158
def get(self, multihash, **kwargs):
159159
"""Get and serialize the DAG node named by multihash.
160-
160+
161161
.. code-block:: python
162162
163163
>>> client.object.get('QmTkzDwWqPbnAh5YiV5VwcTLnGdwSNsNTn2aDxdXBFca7D')
@@ -269,7 +269,7 @@ def put(self, file, **kwargs):
269269
270270
Parameters
271271
----------
272-
file : io.RawIOBase
272+
file : str | bytes | os.PathLike | io.IOBase | int
273273
(JSON) object from which the DAG object will be created
274274
275275
Returns

0 commit comments

Comments
 (0)