Skip to content

Commit

Permalink
deprecate __version__
Browse files Browse the repository at this point in the history
  • Loading branch information
davidism committed Apr 13, 2024
1 parent 05c805f commit 672f44b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Unreleased
- Use modern packaging metadata with ``pyproject.toml`` instead of ``setup.cfg``.
:pr:`326`
- Use ``flit_core`` instead of ``setuptools`` as build backend.
- Deprecate the ``__version__`` attribute. Use feature detection, or
``importlib.metadata.version("itsdangerous")``, instead. :issue:`2770`


Version 2.1.2
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[project]
name = "itsdangerous"
version = "2.2.0.dev"
description = "Safely pass data to untrusted environments and back."
readme = "README.md"
license = { file = "LICENSE.txt" }
Expand All @@ -13,7 +14,6 @@ classifiers = [
"Typing :: Typed",
]
requires-python = ">=3.7"
dynamic = ["version"]

[project.urls]
Donate = "https://palletsprojects.com/donate"
Expand Down
21 changes: 20 additions & 1 deletion src/itsdangerous/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
from __future__ import annotations

import typing as t

from .encoding import base64_decode as base64_decode
from .encoding import base64_encode as base64_encode
from .encoding import want_bytes as want_bytes
Expand All @@ -16,4 +20,19 @@
from .url_safe import URLSafeSerializer as URLSafeSerializer
from .url_safe import URLSafeTimedSerializer as URLSafeTimedSerializer

__version__ = "2.2.0.dev0"

def __getattr__(name: str) -> t.Any:
if name == "__version__":
import importlib.metadata
import warnings

warnings.warn(
"The '__version__' attribute is deprecated and will be removed in"
" ItsDangerous 2.3. Use feature detection or"
" 'importlib.metadata.version(\"itsdangerous\")' instead.",
DeprecationWarning,
stacklevel=2,
)
return importlib.metadata.version("itsdangerous")

raise AttributeError(name)

0 comments on commit 672f44b

Please sign in to comment.