From 859072ee9e45cd99938966126c53ade4adaf10d8 Mon Sep 17 00:00:00 2001 From: Arkadiy Illarionov Date: Sat, 22 Jun 2024 16:02:24 +0300 Subject: [PATCH 1/3] Use typing_extensions only when needed Self was added in Python 3.11 TypeAlias was added in Python 3.10 --- beets/util/__init__.py | 6 +++++- beetsplug/aura.py | 7 ++++++- docs/changelog.rst | 1 + pyproject.toml | 2 +- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/beets/util/__init__.py b/beets/util/__init__.py index 8cbbda8f9..3ce187f02 100644 --- a/beets/util/__init__.py +++ b/beets/util/__init__.py @@ -45,7 +45,11 @@ from typing import ( Union, ) -from typing_extensions import TypeAlias +try: + # Python 3.10+ + from typing import TypeAlias +except ImportError: + from typing_extensions import TypeAlias from unidecode import unidecode from beets.util import hidden diff --git a/beetsplug/aura.py b/beetsplug/aura.py index 35c3e919f..b02dd85f2 100644 --- a/beetsplug/aura.py +++ b/beetsplug/aura.py @@ -29,7 +29,12 @@ from flask import ( request, send_file, ) -from typing_extensions import Self + +try: + # Python 3.11+ + from typing import Self +except ImportError: + from typing_extensions import Self from beets import config from beets.dbcore.query import ( diff --git a/docs/changelog.rst b/docs/changelog.rst index 3725e4993..6219437a9 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -15,6 +15,7 @@ For packagers: * The minimum supported Python version is now 3.8. * The `beet` script has been removed from the repository. +* The `typing_extensions` is required for Python 3.10 and below. Other changes: diff --git a/pyproject.toml b/pyproject.toml index 3ef11ac14..be239a0ec 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,7 +41,7 @@ mediafile = ">=0.12.0" munkres = ">=1.0.0" musicbrainzngs = ">=0.4" pyyaml = "*" -typing_extensions = "*" +typing_extensions = { version = "*", python = "<=3.10" } unidecode = ">=1.3.6" beautifulsoup4 = { version = "*", optional = true } dbus-python = { version = "*", optional = true } From 89f1bda4e0ada4d97e1ef9c4afd35b3bde5e6f5e Mon Sep 17 00:00:00 2001 From: Arkadiy Illarionov Date: Sat, 22 Jun 2024 16:18:56 +0300 Subject: [PATCH 2/3] Update poetry.lock --- poetry.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/poetry.lock b/poetry.lock index 1e3b4cd1d..f7d53578a 100644 --- a/poetry.lock +++ b/poetry.lock @@ -2720,4 +2720,4 @@ web = ["flask", "flask-cors"] [metadata] lock-version = "2.0" python-versions = ">=3.8,<4" -content-hash = "740281ee3ddba4c6015eab9cfc24bb947e8816e3b7f5a6bebeb39ff2413d7ac3" +content-hash = "48fba7c7149c8cb7824f96329bd469a9e9c84b13d233f957889b8b1d7076392f" From 1c020b8264fd03673126f71231393a9a635d585f Mon Sep 17 00:00:00 2001 From: Arkadiy Illarionov Date: Sat, 22 Jun 2024 19:55:52 +0300 Subject: [PATCH 3/3] Check Python version instead of catching ImportError --- beets/util/__init__.py | 6 +++--- beetsplug/aura.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/beets/util/__init__.py b/beets/util/__init__.py index 3ce187f02..7079db444 100644 --- a/beets/util/__init__.py +++ b/beets/util/__init__.py @@ -45,11 +45,11 @@ from typing import ( Union, ) -try: - # Python 3.10+ +if sys.version_info >= (3, 10): from typing import TypeAlias -except ImportError: +else: from typing_extensions import TypeAlias + from unidecode import unidecode from beets.util import hidden diff --git a/beetsplug/aura.py b/beetsplug/aura.py index b02dd85f2..09d859200 100644 --- a/beetsplug/aura.py +++ b/beetsplug/aura.py @@ -17,6 +17,7 @@ import os import re +import sys from dataclasses import dataclass from mimetypes import guess_type from typing import ClassVar, Mapping, Type @@ -30,10 +31,9 @@ from flask import ( send_file, ) -try: - # Python 3.11+ +if sys.version_info >= (3, 11): from typing import Self -except ImportError: +else: from typing_extensions import Self from beets import config