Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deprecate __version__ attribute #402

Merged
merged 2 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)