aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaymond Hettinger <rhettinger@users.noreply.github.com>2019-06-08 08:58:11 -0700
committerGitHub <noreply@github.com>2019-06-08 08:58:11 -0700
commite119b3d136bd94d880bce4b382096f6de3f38062 (patch)
tree241356f01ba320f5b0b342e004902e1e40314a17 /Modules/mathmodule.c
parentbpo-34886: Fix subprocess.run handling of exclusive arguments (GH-11727) (diff)
downloadcpython-e119b3d136bd94d880bce4b382096f6de3f38062.tar.gz
cpython-e119b3d136bd94d880bce4b382096f6de3f38062.tar.bz2
cpython-e119b3d136bd94d880bce4b382096f6de3f38062.zip
bpo-37178: Allow a one argument form of math.perm() (GH-13905)
Diffstat (limited to 'Modules/mathmodule.c')
-rw-r--r--Modules/mathmodule.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c
index 9a9a8159ced..ed114767530 100644
--- a/Modules/mathmodule.c
+++ b/Modules/mathmodule.c
@@ -3002,7 +3002,7 @@ math_prod_impl(PyObject *module, PyObject *iterable, PyObject *start)
math.perm
n: object
- k: object
+ k: object = None
/
Number of ways to choose k items from n items without repetition and with order.
@@ -3010,18 +3010,24 @@ Number of ways to choose k items from n items without repetition and with order.
Evaluates to n! / (n - k)! when k <= n and evaluates
to zero when k > n.
+If k is not specified or is None, then k defaults to n
+and the function returns n!.
+
Raises TypeError if either of the arguments are not integers.
Raises ValueError if either of the arguments are negative.
[clinic start generated code]*/
static PyObject *
math_perm_impl(PyObject *module, PyObject *n, PyObject *k)
-/*[clinic end generated code: output=e021a25469653e23 input=b2e7729d9a1949cf]*/
+/*[clinic end generated code: output=e021a25469653e23 input=5311c5a00f359b53]*/
{
PyObject *result = NULL, *factor = NULL;
int overflow, cmp;
long long i, factors;
+ if (k == Py_None) {
+ return math_factorial(module, n);
+ }
n = PyNumber_Index(n);
if (n == NULL) {
return NULL;