Skip to content

Commit 033fe1e

Browse files
authored
change docstring format (#26)
* use sphinx-style docstrings
1 parent 4fe78cc commit 033fe1e

1 file changed

Lines changed: 88 additions & 142 deletions

File tree

src/metrohash.pyx

Lines changed: 88 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -103,18 +103,14 @@ cdef object _type_error(argname: str, expected: object, value: object):
103103

104104

105105
cpdef bytes hash64(data, uint64 seed=0ULL):
106-
"""
107-
Obtain a 64-bit hash from data using MetroHash-64.
108-
109-
Args:
110-
data (str or buffer): input data (either string or buffer type)
111-
seed (int): seed to random number generator
112-
Returns:
113-
bytes: hash value
114-
Raises:
115-
TypeError: if input data is not a string or a buffer
116-
ValueError: if input buffer is not C-contiguous
117-
OverflowError: if seed cannot be converted to unsigned int64
106+
"""Obtain a 64-bit hash from data using MetroHash-64.
107+
108+
:param data: input data (either string or buffer type)
109+
:param seed: seed to random number generator (integer)
110+
:return: hash value (bytes)
111+
:raises TypeError: if input data is not a string or a buffer
112+
:raises ValueError: if input buffer is not C-contiguous
113+
:raises OverflowError: if seed cannot be converted to unsigned int64
118114
"""
119115
cdef Py_buffer buf
120116
cdef bytearray out = bytearray(8)
@@ -138,18 +134,14 @@ Raises:
138134

139135

140136
cpdef bytes hash128(data, uint64 seed=0ULL):
141-
"""
142-
Obtain a 128-bit hash from data using MetroHash-128.
143-
144-
Args:
145-
data (str or buffer): input data (either string or buffer type)
146-
seed (int): seed to random number generator
147-
Returns:
148-
bytes: hash value
149-
Raises:
150-
TypeError: if input data is not a string or a buffer
151-
ValueError: if input buffer is not C-contiguous
152-
OverflowError: if seed cannot be converted to unsigned int64
137+
"""Obtain a 128-bit hash from data using MetroHash-128.
138+
139+
:param data: input data (either string or buffer type)
140+
:param seed: seed to random number generator (integer)
141+
:return: hash value (bytes)
142+
:raises TypeError: if input data is not a string or a buffer
143+
:raises ValueError: if input buffer is not C-contiguous
144+
:raises OverflowError: if seed cannot be converted to unsigned int64
153145
"""
154146
cdef Py_buffer buf
155147
cdef bytearray out = bytearray(16)
@@ -174,52 +166,40 @@ Raises:
174166

175167

176168
def hash64_hex(data, uint64 seed=0ULL) -> str:
177-
"""
178-
Obtain a 64-bit hash from data using MetroHash-64.
179-
180-
Args:
181-
data (str or buffer): input data (either string or buffer type)
182-
seed (int): seed to random number generator
183-
Returns:
184-
str: hash value
185-
Raises:
186-
TypeError: if input data is not a string or a buffer
187-
ValueError: if input buffer is not C-contiguous
188-
OverflowError: if seed cannot be converted to unsigned int64
169+
"""Obtain a 64-bit hash from data using MetroHash-64.
170+
171+
:param data: input data (either string or buffer type)
172+
:param seed: seed to random number generator (integer)
173+
:return: hash value (string)
174+
:raises TypeError: if input data is not a string or a buffer
175+
:raises ValueError: if input buffer is not C-contiguous
176+
:raises OverflowError: if seed cannot be converted to unsigned int64
189177
"""
190178
return bytes2hex(hash64(data, seed=seed))
191179

192180

193181
def hash128_hex(data, uint64 seed=0ULL) -> str:
194-
"""
195-
Obtain a 128-bit hash from data using MetroHash-128.
196-
197-
Args:
198-
data (str or buffer): input data (either string or buffer type)
199-
seed (int): seed to random number generator
200-
Returns:
201-
str: hash value
202-
Raises:
203-
TypeError: if input data is not a string or a buffer
204-
ValueError: if input buffer is not C-contiguous
205-
OverflowError: if seed cannot be converted to unsigned int64
182+
"""Obtain a 128-bit hash from data using MetroHash-128.
183+
184+
:param data: data (either string or buffer type)
185+
:param seed: seed to random number generator (integer)
186+
:return: hash value (string)
187+
:raises TypeError: if input data is not a string or a buffer
188+
:raises ValueError: if input buffer is not C-contiguous
189+
:raises OverflowError: if seed cannot be converted to unsigned int64
206190
"""
207191
return bytes2hex(hash128(data, seed=seed))
208192

209193

210194
def hash64_int(data, uint64 seed=0ULL) -> int:
211-
"""
212-
Obtain a 64-bit hash from data using MetroHash-64.
213-
214-
Args:
215-
data (str or buffer): input data (either string or buffer type)
216-
seed (int): seed to random number generator
217-
Returns:
218-
int: hash value
219-
Raises:
220-
TypeError: if input data is not a string or a buffer
221-
ValueError: if input buffer is not C-contiguous
222-
OverflowError: if seed cannot be converted to unsigned int64
195+
"""Obtain a 64-bit hash from data using MetroHash-64.
196+
197+
:param data: input data (either string or buffer type)
198+
:param seed: seed to random number generator (integer)
199+
:return: hash value (integer)
200+
:raises TypeError: if input data is not a string or a buffer
201+
:raises ValueError: if input buffer is not C-contiguous
202+
:raises OverflowError: if seed cannot be converted to unsigned int64
223203
"""
224204
cdef Py_buffer buf
225205
cdef uint64 result
@@ -243,18 +223,14 @@ Raises:
243223

244224

245225
def hash128_int(data, uint64 seed=0ULL) -> int:
246-
"""
247-
Obtain a 128-bit hash from data using MetroHash-128.
248-
249-
Args:
250-
data (str or buffer): input data (either string or buffer type)
251-
seed (int): seed to random number generator
252-
Returns:
253-
int: hash value
254-
Raises:
255-
TypeError: if input data is not a string or a buffer
256-
ValueError: if input buffer is not C-contiguous
257-
OverflowError: if seed cannot be converted to unsigned int64
226+
"""Obtain a 128-bit hash from data using MetroHash-128.
227+
228+
:param data: input data (either string or buffer type)
229+
:param seed: seed to random number generator (integer)
230+
:return: hash value (integer)
231+
:raises TypeError: if input data is not a string or a buffer
232+
:raises ValueError: if input buffer is not C-contiguous
233+
:raises OverflowError: if seed cannot be converted to unsigned int64
258234
"""
259235
cdef Py_buffer buf
260236
cdef uint128 result
@@ -278,15 +254,12 @@ Raises:
278254

279255

280256
cdef class MetroHash64(object):
281-
"""
282-
Incremental hasher interface for MetroHash-64.
283-
284-
Args:
285-
seed (int): seed to random number generator
286-
Raises:
287-
TypeError: if seed is not an integer type
288-
MemoryError: if a new method fails
289-
OverflowError: if seed is out of bounds
257+
"""Incremental hasher interface for MetroHash-64.
258+
259+
:param seed: seed to random number generator (integer)
260+
:raises TypeError: if seed is not an integer type
261+
:raises MemoryError: if a new method fails
262+
:raises OverflowError: if seed is out of bounds
290263
"""
291264

292265
cdef CCMetroHash64* _m
@@ -302,26 +275,20 @@ Raises:
302275
self._m = NULL
303276

304277
def reset(self, uint64 seed=0ULL) -> None:
305-
"""
306-
Reset state with a new seed.
278+
"""Reset state with a new seed.
307279

308-
Args:
309-
seed (int): new seed to reset state to
310-
Raises:
311-
TypeError: if seed is not an integer type
312-
OverflowError: if seed is out of bounds
280+
:param seed: new seed to reset state to (integer)
281+
:raises TypeError: if seed is not an integer type
282+
:raises OverflowError: if seed is out of bounds
313283
"""
314284
self._m.Initialize(seed)
315285

316286
def update(self, data) -> None:
317-
"""
318-
Update digest with new data.
287+
"""Update digest with new data.
319288

320-
Args:
321-
data (str or buffer): input data (either string or buffer type)
322-
Raises:
323-
TypeError: if input data is not a string or a buffer
324-
ValueError: if input buffer is not C-contiguous
289+
:param data: input data (either string or buffer type)
290+
:raises TypeError: if input data is not a string or a buffer
291+
:raises ValueError: if input buffer is not C-contiguous
325292
"""
326293
cdef Py_buffer buf
327294
cdef const char* encoding
@@ -342,47 +309,38 @@ Raises:
342309
raise _type_error("data", ["basestring", "buffer"], data)
343310

344311
cpdef bytes digest(self):
345-
"""
346-
Obtain bytes digest.
312+
"""Obtain bytes digest.
347313
348-
Returns:
349-
bytes: eight bytes representing the 64-bit hash
314+
:return: eight bytes representing the 64-bit hash
350315
"""
351316
cdef bytearray out = bytearray(8)
352317
self._m.Finalize(out)
353318
return bytes(out)
354319

355320
def hexdigest(self) -> str:
356-
"""
357-
Obtain a string digest in hexadecimal form.
321+
"""Obtain a string digest in hexadecimal form.
358322

359-
Returns:
360-
str: hash string
323+
:return: hash string
361324
"""
362325
return bytes2hex(self.digest())
363326

364327
def intdigest(self) -> int:
365-
"""
366-
Obtain a long integer representing hash value.
328+
"""Obtain a long integer representing hash value.
367329

368-
Returns:
369-
int: an integer representing 64-bit hash value
330+
:return: an integer representing 64-bit hash value
370331
"""
371332
cdef uint8 buf[8]
372333
self._m.Finalize(buf)
373334
return c_bytes2int64(buf)
374335

375336

376337
cdef class MetroHash128(object):
377-
"""
378-
Incremental hasher interface for MetroHash-128.
379-
380-
Args:
381-
seed (int): seed to random number generator
382-
Raises:
383-
TypeError: if seed is not an integer type
384-
MemoryError: if a new method fails
385-
OverflowError: if seed is out of bounds
338+
"""Incremental hasher interface for MetroHash-128.
339+
340+
:param seed: seed to random number generator (integer)
341+
:raises TypeError: if seed is not an integer type
342+
:raises MemoryError: if a new method fails
343+
:raises OverflowError: if seed is out of bounds
386344
"""
387345

388346
cdef CCMetroHash128* _m
@@ -398,26 +356,20 @@ Raises:
398356
self._m = NULL
399357

400358
def reset(self, uint64 seed=0ULL) -> None:
401-
"""
402-
Reset state with a new seed.
359+
"""Reset state with a new seed.
403360

404-
Args:
405-
seed (int): new seed to reset state to
406-
Raises:
407-
TypeError: if seed is not an integer type
408-
OverflowError: if seed is out of bounds
361+
:param seed: new seed to reset state to (integer)
362+
:param TypeError: if seed is not an integer type
363+
:param OverflowError: if seed is out of bounds
409364
"""
410365
self._m.Initialize(seed)
411366

412367
def update(self, data) -> None:
413-
"""
414-
Update digest with new data.
368+
"""Update digest with new data.
415369

416-
Args:
417-
data (str or buffer): input data (either string or buffer type)
418-
Raises:
419-
TypeError: if input data is not a string or a buffer
420-
ValueError: if input buffer is not C-contiguous
370+
:param data: input data (either string or buffer type)
371+
:raises TypeError: if input data is not a string or a buffer
372+
:raises ValueError: if input buffer is not C-contiguous
421373
"""
422374
cdef Py_buffer buf
423375
cdef const char* encoding
@@ -438,31 +390,25 @@ Raises:
438390
raise _type_error("data", ["basestring", "buffer"], data)
439391

440392
cpdef bytes digest(self):
441-
"""
442-
Obtain bytes digest.
393+
"""Obtain bytes digest.
443394
444-
Returns:
445-
bytes: sixteen bytes representing the 128-bit hash
395+
:return: sixteen bytes representing the 128-bit hash
446396
"""
447397
cdef bytearray out = bytearray(16)
448398
self._m.Finalize(out)
449399
return bytes(out)
450400

451401
def hexdigest(self) -> str:
452-
"""
453-
Obtain a string digest in hexadecimal form.
402+
"""Obtain a string digest in hexadecimal form.
454403

455-
Returns:
456-
str: hash string
404+
:return: hash string
457405
"""
458406
return bytes2hex(self.digest())
459407

460408
def intdigest(self) -> int:
461-
"""
462-
Obtain integer digest.
409+
"""Obtain integer digest.
463410

464-
Returns:
465-
int: a long integer representing 128-bit hash value
411+
:return: a long integer representing 128-bit hash value
466412
"""
467413
cdef uint8 buf[16]
468414
self._m.Finalize(buf)

0 commit comments

Comments
 (0)