From f7db50387767e3052ec6fc604df8481f483abe74 Mon Sep 17 00:00:00 2001 From: Hsiaoming Yang Date: Thu, 24 Oct 2024 18:10:52 +0900 Subject: [PATCH] fix: make typing-extension optional dependency --- pyproject.toml | 3 +-- src/mistune/__init__.py | 9 +++++---- src/mistune/core.py | 2 +- src/mistune/list_parser.py | 2 -- src/mistune/renderers/html.py | 5 +---- 5 files changed, 8 insertions(+), 13 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 5a8247a..5e0883c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ name = "mistune" description = "A sane and fast Markdown parser with useful plugins and renderers" authors = [{name = "Hsiaoming Yang", email="me@lepture.com"}] dependencies = [ - "typing-extensions", + "typing-extensions; python_version<'3.11'", ] license = {text = "BSD-3-Clause"} dynamic = ["version"] @@ -18,7 +18,6 @@ classifiers = [ "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", diff --git a/src/mistune/__init__.py b/src/mistune/__init__.py index 9448eae..bf27c84 100644 --- a/src/mistune/__init__.py +++ b/src/mistune/__init__.py @@ -8,10 +8,11 @@ Documentation: https://mistune.lepture.com/ """ -from typing import Any, Dict, Iterable, List, Optional, Tuple, Union - -from typing_extensions import Literal - +try: + import typing_extensions +except ImportError: + pass +from typing import Any, Dict, Iterable, List, Optional, Tuple, Union, Literal from .block_parser import BlockParser from .core import BaseRenderer, BlockState, InlineState from .inline_parser import InlineParser diff --git a/src/mistune/core.py b/src/mistune/core.py index 05a2d20..7c23cd1 100644 --- a/src/mistune/core.py +++ b/src/mistune/core.py @@ -14,9 +14,9 @@ Type, TypeVar, Union, + Self, cast, ) -from typing_extensions import Self _LINE_END = re.compile(r'\n|$') diff --git a/src/mistune/list_parser.py b/src/mistune/list_parser.py index 4609992..7b9682e 100644 --- a/src/mistune/list_parser.py +++ b/src/mistune/list_parser.py @@ -2,8 +2,6 @@ import re from typing import TYPE_CHECKING, Any, Dict, Iterable, List, Optional, Tuple, Match - - from .util import expand_leading_tab, expand_tab, strip_end if TYPE_CHECKING: diff --git a/src/mistune/renderers/html.py b/src/mistune/renderers/html.py index f8e86d7..0d999a7 100644 --- a/src/mistune/renderers/html.py +++ b/src/mistune/renderers/html.py @@ -1,7 +1,4 @@ -from typing import Any, ClassVar, Dict, Optional, Tuple - -from typing_extensions import Literal - +from typing import Any, ClassVar, Dict, Optional, Tuple, Literal from ..core import BaseRenderer, BlockState from ..util import escape as escape_text from ..util import safe_entity, striptags