diff --git a/confuse/core.py b/confuse/core.py index 41cb5d6..d1b117e 100644 --- a/confuse/core.py +++ b/confuse/core.py @@ -33,8 +33,12 @@ from collections import OrderedDict from typing import TYPE_CHECKING, Any, TypeVar, overload +try: + from typing import Self +except ImportError: # Python < 3.11 + from typing_extensions import Self + import yaml -from typing_extensions import Self from . import templates, util, yaml_util from .exceptions import ConfigError, ConfigTypeError, NotFoundError diff --git a/confuse/templates.py b/confuse/templates.py index 55bbd7c..a706765 100644 --- a/confuse/templates.py +++ b/confuse/templates.py @@ -4,12 +4,16 @@ import os import pathlib import re +import sys from collections import abc from collections.abc import Hashable, Iterable, Mapping from functools import singledispatchmethod from typing import TYPE_CHECKING, Any, Generic, NoReturn, overload -from typing_extensions import TypeVar +if sys.version_info < (3, 13): + from typing_extensions import TypeVar +else: + from typing import TypeVar from . import exceptions, util diff --git a/docs/changelog.rst b/docs/changelog.rst index 1e2c5c0..e60c61c 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -1,6 +1,12 @@ Changelog ========= +Unreleased +----------- +- Require `typing_extensions` on older Python versions (and use `typing` + on newer versions). [#189](https://github.com/beetbox/confuse/issues/189) + + v2.2.0 ------ diff --git a/pyproject.toml b/pyproject.toml index cbf03c9..835f816 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,6 +18,7 @@ classifiers = [ ] dependencies = [ "pyyaml", + "typing_extensions >= 4.4; python_version < '1.13'", ] [dependency-groups]