Skip to content

Commit

Permalink
Merge pull request #240 from hugovk/deprecate-VERSION
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk authored Nov 29, 2021
2 parents 5aba062 + 710ca33 commit f9fa838
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
[![Tidelift](https://tidelift.com/badges/package/pypi/humanize)](https://tidelift.com/subscription/pkg/pypi-humanize?utm_source=pypi-humanize&utm_medium=badge)

This modest package contains various common humanization utilities, like turning
a number into a fuzzy human readable duration ("3 minutes ago") or into a human
readable size or throughput. It is localized to:
a number into a fuzzy human-readable duration ("3 minutes ago") or into a
human-readable size or throughput. It is localized to:

* Bengali
* Brazilian Portuguese
Expand Down
22 changes: 22 additions & 0 deletions src/humanize/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
"""Main package for humanize."""

import sys
import warnings

from humanize.filesize import naturalsize
from humanize.i18n import activate, deactivate, thousands_separator
from humanize.number import (
Expand Down Expand Up @@ -29,6 +32,25 @@
__version__ = importlib_metadata.version(__name__)


if sys.version_info >= (3, 7):
# This technique isn't available for 3.6 but we don't need to warn for 3.6
# because we'll drop 3.6 at the same time as removing this
def __getattr__(name):
if name == "VERSION":
warnings.warn(
"VERSION is deprecated and will be removed in humanize 4.0. "
"Use __version__ instead, available since humanize 1.0 (Feb 2020).",
DeprecationWarning,
stacklevel=2,
)
return __version__
raise AttributeError(f"module '{__name__}' has no attribute '{name}'")


else:
VERSION = __version__


__all__ = [
"__version__",
"activate",
Expand Down
16 changes: 16 additions & 0 deletions tests/test_humanize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""Other tests."""
import sys

import pytest

import humanize


def test_version():
if sys.version_info >= (3, 7):
with pytest.warns(DeprecationWarning):
VERSION = humanize.VERSION
else:
VERSION = humanize.VERSION

assert VERSION == humanize.__version__
1 change: 1 addition & 0 deletions tests/test_i18n.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Internationalisation tests."""
import datetime as dt
import importlib

Expand Down
2 changes: 0 additions & 2 deletions tests/test_number.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env python

"""Number tests."""

import pytest
Expand Down
2 changes: 0 additions & 2 deletions tests/test_time.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env python

"""Tests for time humanizing."""

import datetime as dt
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ commands =
pre-commit run --all-files --show-diff-on-failure

[pytest]
addopts = --doctest-modules
addopts = --color=yes --doctest-modules

0 comments on commit f9fa838

Please sign in to comment.