diff --git a/pyproject.toml b/pyproject.toml index 5c3b252..c28114c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,6 +26,9 @@ classifiers = [ "Programming Language :: Python :: 3.13", "Topic :: Software Development :: Libraries", ] +dependencies = [ + "typing-extensions; python_version < '3.11'", +] [project.urls] Homepage = "https://github.com/mdomke/python-ulid" diff --git a/ulid/__init__.py b/ulid/__init__.py index d327385..bba8873 100644 --- a/ulid/__init__.py +++ b/ulid/__init__.py @@ -13,19 +13,23 @@ from typing import TYPE_CHECKING from typing import TypeVar -from typing_extensions import Self - from ulid import base32 from ulid import constants if TYPE_CHECKING: # pragma: no cover + import sys from collections.abc import Callable from pydantic import GetCoreSchemaHandler from pydantic import ValidatorFunctionWrapHandler from pydantic_core import CoreSchema + if sys.version_info >= (3, 11): + from typing import Self + else: + from typing_extensions import Self + try: from importlib.metadata import version except ImportError: # pragma: no cover @@ -199,7 +203,7 @@ def parse(cls, value: Any) -> Self: a value when they're unsure what format/primitive type it will be given in. """ if isinstance(value, ULID): - return cast(Self, value) + return cast("Self", value) if isinstance(value, uuid.UUID): return cls.from_uuid(value) if isinstance(value, str): diff --git a/uv.lock b/uv.lock index 9818362..1371271 100644 --- a/uv.lock +++ b/uv.lock @@ -825,6 +825,9 @@ wheels = [ [[package]] name = "python-ulid" source = { editable = "." } +dependencies = [ + { name = "typing-extensions", marker = "python_full_version < '3.11'" }, +] [package.optional-dependencies] pydantic = [ @@ -841,7 +844,10 @@ dev = [ ] [package.metadata] -requires-dist = [{ name = "pydantic", marker = "extra == 'pydantic'", specifier = ">=2.0" }] +requires-dist = [ + { name = "pydantic", marker = "extra == 'pydantic'", specifier = ">=2.0" }, + { name = "typing-extensions", marker = "python_full_version < '3.11'" }, +] provides-extras = ["pydantic"] [package.metadata.requires-dev]