Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not issue deprecation warnings during import #244

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 22 additions & 16 deletions src/humanize/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
"precisedelta",
]

_IMPORTING = True


@total_ordering
class _Unit(Enum):
Expand All @@ -44,30 +46,32 @@ class _UnitMeta(EnumMeta):
"""Metaclass for an enum that emits deprecation warnings when accessed."""

def __getattribute__(self, name):
# Temporarily comment out to avoid warning during 'import humanize'
# warnings.warn(
# "`Unit` has been deprecated. "
# "The enum is still available as the private member `_Unit`.",
# DeprecationWarning,
# )
if not _IMPORTING:
warnings.warn(
"`Unit` has been deprecated. "
"The enum is still available as the private member `_Unit`.",
DeprecationWarning,
)
return EnumMeta.__getattribute__(_Unit, name)

def __getitem__(cls, name):
warnings.warn(
"`Unit` has been deprecated. "
"The enum is still available as the private member `_Unit`.",
DeprecationWarning,
)
if not _IMPORTING:
warnings.warn(
"`Unit` has been deprecated. "
"The enum is still available as the private member `_Unit`.",
DeprecationWarning,
)
return _Unit.__getitem__(name)

def __call__(
cls, value, names=None, *, module=None, qualname=None, type=None, start=1
):
warnings.warn(
"`Unit` has been deprecated. "
"The enum is still available as the private member `_Unit`.",
DeprecationWarning,
)
if not _IMPORTING:
warnings.warn(
"`Unit` has been deprecated. "
"The enum is still available as the private member `_Unit`.",
DeprecationWarning,
)
return _Unit.__call__(
value, names, module=module, qualname=qualname, type=type, start=start
)
Expand Down Expand Up @@ -618,3 +622,5 @@ def precisedelta(value, minimum_unit="seconds", suppress=(), format="%0.2f") ->
tail = texts[-1]

return _("%s and %s") % (head, tail)

_IMPORTING = False