Skip to content

Commit 2a79109

Browse files
committed
add docstrings
1 parent c43eefe commit 2a79109

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

entropymodule.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,28 @@
88

99
static PyObject *shannon_entropy(PyObject *, PyObject *);
1010

11+
PyDoc_STRVAR(module_doc,
12+
"Fast entropy calculation.\n"
13+
"\n"
14+
"This module provides a method implemented in C for calculating the\n"
15+
"shannon entropy of a byte string.");
16+
17+
PyDoc_STRVAR(shannon_entropy_doc,
18+
"shannon_entropy(bytes) -> float\n"
19+
"\n"
20+
"H(S) = - Sum(p_i * log(p_i))\n");
21+
1122

1223
static PyMethodDef entropy_methods[] = {
13-
{"shannon_entropy",
14-
shannon_entropy, METH_VARARGS, "Calculate entropy of bytestring."},
24+
{"shannon_entropy", shannon_entropy, METH_VARARGS, shannon_entropy_doc},
1525
{NULL, NULL, 0, NULL}
1626
};
1727

1828
#if PY_MAJOR_VERSION >= 3
1929
static struct PyModuleDef moduledef = {
2030
PyModuleDef_HEAD_INIT,
2131
"entropy",
22-
NULL,
32+
module_doc,
2333
0,
2434
entropy_methods,
2535
NULL,
@@ -38,7 +48,7 @@ PyInit_entropy(void)
3848
PyMODINIT_FUNC
3949
initentropy(void)
4050
{
41-
Py_InitModule("entropy", entropy_methods);
51+
Py_InitModule3("entropy", entropy_methods, module_doc);
4252
}
4353
#endif
4454

0 commit comments

Comments
 (0)