Skip to content

Commit

Permalink
deprecate __version__ attribute (pallets#2599)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidism authored Aug 30, 2023
2 parents a327751 + d8fa6a0 commit b63ace2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,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("click")``, instead. :issue:`2598`
- ``BaseCommand`` is deprecated. ``Command`` is the base class for all
commands. :issue:`2589`
- ``MultiCommand`` is deprecated. ``Group`` is the base class for all group
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 = "click"
version = "8.2.0.dev"
description = "Composable command line interface toolkit"
readme = "README.rst"
license = {file = "LICENSE.rst"}
Expand All @@ -15,7 +16,6 @@ requires-python = ">=3.8"
dependencies = [
"colorama; platform_system == 'Windows'",
]
dynamic = ["version"]

[project.urls]
Donate = "https://palletsprojects.com/donate"
Expand Down
15 changes: 13 additions & 2 deletions src/click/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@
from .utils import get_text_stream as get_text_stream
from .utils import open_file as open_file

__version__ = "8.2.0.dev0"


def __getattr__(name: str) -> object:
import warnings
Expand Down Expand Up @@ -108,4 +106,17 @@ def __getattr__(name: str) -> object:
)
return _OptionParser

if name == "__version__":
import importlib.metadata
import warnings

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

raise AttributeError(name)

0 comments on commit b63ace2

Please sign in to comment.