Skip to content

Commit f9fa838

Browse files
authored
Merge pull request #240 from hugovk/deprecate-VERSION
2 parents 5aba062 + 710ca33 commit f9fa838

7 files changed

Lines changed: 42 additions & 7 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
[![Tidelift](https://tidelift.com/badges/package/pypi/humanize)](https://tidelift.com/subscription/pkg/pypi-humanize?utm_source=pypi-humanize&utm_medium=badge)
1111

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

1616
* Bengali
1717
* Brazilian Portuguese

src/humanize/__init__.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
"""Main package for humanize."""
22

3+
import sys
4+
import warnings
5+
36
from humanize.filesize import naturalsize
47
from humanize.i18n import activate, deactivate, thousands_separator
58
from humanize.number import (
@@ -29,6 +32,25 @@
2932
__version__ = importlib_metadata.version(__name__)
3033

3134

35+
if sys.version_info >= (3, 7):
36+
# This technique isn't available for 3.6 but we don't need to warn for 3.6
37+
# because we'll drop 3.6 at the same time as removing this
38+
def __getattr__(name):
39+
if name == "VERSION":
40+
warnings.warn(
41+
"VERSION is deprecated and will be removed in humanize 4.0. "
42+
"Use __version__ instead, available since humanize 1.0 (Feb 2020).",
43+
DeprecationWarning,
44+
stacklevel=2,
45+
)
46+
return __version__
47+
raise AttributeError(f"module '{__name__}' has no attribute '{name}'")
48+
49+
50+
else:
51+
VERSION = __version__
52+
53+
3254
__all__ = [
3355
"__version__",
3456
"activate",

tests/test_humanize.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""Other tests."""
2+
import sys
3+
4+
import pytest
5+
6+
import humanize
7+
8+
9+
def test_version():
10+
if sys.version_info >= (3, 7):
11+
with pytest.warns(DeprecationWarning):
12+
VERSION = humanize.VERSION
13+
else:
14+
VERSION = humanize.VERSION
15+
16+
assert VERSION == humanize.__version__

tests/test_i18n.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"""Internationalisation tests."""
12
import datetime as dt
23
import importlib
34

tests/test_number.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python
2-
31
"""Number tests."""
42

53
import pytest

tests/test_time.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python
2-
31
"""Tests for time humanizing."""
42

53
import datetime as dt

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ commands =
2626
pre-commit run --all-files --show-diff-on-failure
2727

2828
[pytest]
29-
addopts = --doctest-modules
29+
addopts = --color=yes --doctest-modules

0 commit comments

Comments
 (0)