From bbdd173b9083b9606eb0eeed25790f83c33b7c14 Mon Sep 17 00:00:00 2001 From: Daniel Ching Date: Mon, 13 Dec 2021 18:59:45 -0600 Subject: [PATCH 1/4] DOC: Deprecate naturaldelta(when) --- src/humanize/time.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/humanize/time.py b/src/humanize/time.py index ed68532..8e37cff 100644 --- a/src/humanize/time.py +++ b/src/humanize/time.py @@ -173,6 +173,9 @@ def naturaldelta( minimum_unit (str): The lowest unit that can be used. when (datetime.datetime): Point in time relative to which _value_ is interpreted. Defaults to the current time in the local timezone. + .. deprecated:: 3.13 + If you need to construct a timedelta, do it inline as the first + argument. Returns: str: A natural representation of the amount of time elapsed. @@ -189,6 +192,14 @@ def naturaldelta( assert naturaldelta(later, when=now) == "30 minutes" """ + if when: + warnings.warn( + "The `when` parameter of naturaldelta() is deprecated and will be " + "removed in humanize 4.0. If you need to construct a timedelta, " + "do it inline as the first argument.", + DeprecationWarning, + stacklevel=2, + ) tmp = _Unit[minimum_unit.upper()] if tmp not in (_Unit.SECONDS, _Unit.MILLISECONDS, _Unit.MICROSECONDS): raise ValueError(f"Minimum unit '{minimum_unit}' not supported") From 138b092ab2f9903efa9ddf96f5337b98be8eaf55 Mon Sep 17 00:00:00 2001 From: Daniel Ching Date: Wed, 15 Dec 2021 11:26:37 -0600 Subject: [PATCH 2/4] Use correct deprecation version for naturaldelta(..., when) Co-authored-by: Hugo van Kemenade --- src/humanize/time.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/humanize/time.py b/src/humanize/time.py index 8e37cff..7f07769 100644 --- a/src/humanize/time.py +++ b/src/humanize/time.py @@ -173,7 +173,7 @@ def naturaldelta( minimum_unit (str): The lowest unit that can be used. when (datetime.datetime): Point in time relative to which _value_ is interpreted. Defaults to the current time in the local timezone. - .. deprecated:: 3.13 + .. deprecated:: 3.14 If you need to construct a timedelta, do it inline as the first argument. From 1f19fea84773b6c9d508db2fc3cdb8a55409c0f7 Mon Sep 17 00:00:00 2001 From: Daniel Ching Date: Wed, 15 Dec 2021 11:27:25 -0600 Subject: [PATCH 3/4] Use fixed-width text for all code in warning message Co-authored-by: Hugo van Kemenade --- src/humanize/time.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/humanize/time.py b/src/humanize/time.py index 7f07769..37ef3fc 100644 --- a/src/humanize/time.py +++ b/src/humanize/time.py @@ -194,7 +194,7 @@ def naturaldelta( """ if when: warnings.warn( - "The `when` parameter of naturaldelta() is deprecated and will be " + "The `when` parameter of `naturaldelta()` is deprecated and will be " "removed in humanize 4.0. If you need to construct a timedelta, " "do it inline as the first argument.", DeprecationWarning, From ec49a2d1c0f33dc74e9dde8add06cab58710f077 Mon Sep 17 00:00:00 2001 From: Daniel Ching Date: Wed, 15 Dec 2021 13:47:07 -0600 Subject: [PATCH 4/4] DOC: Remove sphinx directives --- src/humanize/time.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/humanize/time.py b/src/humanize/time.py index 37ef3fc..be7f9ed 100644 --- a/src/humanize/time.py +++ b/src/humanize/time.py @@ -173,9 +173,8 @@ def naturaldelta( minimum_unit (str): The lowest unit that can be used. when (datetime.datetime): Point in time relative to which _value_ is interpreted. Defaults to the current time in the local timezone. - .. deprecated:: 3.14 - If you need to construct a timedelta, do it inline as the first - argument. + Deprecated in version 3.14; If you need to construct a timedelta, + do it inline as the first argument. Returns: str: A natural representation of the amount of time elapsed.