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 trio.__version__ #3190

Closed
wants to merge 5 commits into from
Closed
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
1 change: 1 addition & 0 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ build:
python:
install:
- requirements: docs-requirements.txt
- path: .

sphinx:
fail_on_warning: true
Expand Down
4 changes: 2 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,9 @@ def add_mapping(
# built documents.
#
# The short X.Y version.
import trio
import importlib.metadata

version = trio.__version__
version = importlib.metadata.version("trio")
# The full version, including alpha/beta/rc tags.
release = version

Expand Down
1 change: 1 addition & 0 deletions newsfragments/3190.deprecated.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Deprecate ``trio.__version__`` in favor of `importlib.metadata.version`.
9 changes: 8 additions & 1 deletion src/trio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,14 @@

_deprecate.enable_attribute_deprecations(__name__)

__deprecated_attributes__: dict[str, _deprecate.DeprecatedAttribute] = {}
__deprecated_attributes__: dict[str, _deprecate.DeprecatedAttribute] = {
"__version__": _deprecate.DeprecatedAttribute(
__version__, "0.29.0", issue=None, instead='importlib.metadata.version("trio")'
)
}

if not TYPE_CHECKING:
del __version__

# Having the public path in .__module__ attributes is important for:
# - exception names in printed tracebacks
Expand Down
9 changes: 9 additions & 0 deletions src/trio/_tests/test_trio.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,12 @@ def test_trio_import() -> None:
del sys.modules[module]

import trio # noqa: F401


def test_trio_version_deprecated() -> None:
import pytest

import trio

with pytest.warns(DeprecationWarning, match="^trio.__version__ is deprecated"):
_ = trio.__version__
4 changes: 4 additions & 0 deletions src/trio/_tests/type_tests/trio_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import trio
from typing_extensions import assert_type

assert_type(trio.__version__, str)
Loading