Skip to content

Commit

Permalink
deprecate __version__ attribute (#402)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidism authored Sep 15, 2023
2 parents 562e82e + 8d9c720 commit 4afaf1a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
4 changes: 3 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Version 2.2.0
Version 3.0.0
-------------

Unreleased
Expand All @@ -16,6 +16,8 @@ Unreleased
argument. These methods are conceptually linked to search methods such as
``in``, ``find``, and ``index``, which already do not escape their argument.
:issue:`401`
- The ``__version__`` attribute is deprecated. Use feature detection, or
``importlib.metadata.version("markupsafe")``, instead. :pr:`402`


Version 2.1.3
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 = "MarkupSafe"
version = "3.0.0.dev"
description = "Safely add untrusted strings to HTML/XML markup."
readme = "README.rst"
license = {text = "BSD-3-Clause"}
Expand All @@ -15,7 +16,6 @@ classifiers = [
"Topic :: Text Processing :: Markup :: HTML",
]
requires-python = ">=3.8"
dynamic = ["version"]

[project.urls]
Donate = "https://palletsprojects.com/donate"
Expand Down
18 changes: 16 additions & 2 deletions src/markupsafe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ def __call__(self, s: t.Any, /) -> Markup:
...


__version__ = "2.2.0.dev"

_strip_comments_re = re.compile(r"<!--.*?-->", re.DOTALL)
_strip_tags_re = re.compile(r"<.*?>", re.DOTALL)

Expand Down Expand Up @@ -315,3 +313,19 @@ def __float__(self, /) -> float:
from ._native import escape as escape
from ._native import escape_silent as escape_silent # noqa: F401
from ._native import soft_str as soft_str # noqa: F401


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"
" MarkupSafe 3.1. Use feature detection, or"
' `importlib.metadata.version("markupsafe")`, instead.',
stacklevel=2,
)
return importlib.metadata.version("flask-classful")

raise AttributeError(name)

0 comments on commit 4afaf1a

Please sign in to comment.