Skip to content

Commit c546848

Browse files
committed
Reinstate VERSION and deprecate
1 parent 374f14e commit c546848

3 files changed

Lines changed: 39 additions & 0 deletions

File tree

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

0 commit comments

Comments
 (0)