Skip to content

Commit 11756a1

Browse files
authored
🔧: Depend on typing_extensions only on Python <3.8 (#642)
1 parent 28725fc commit 11756a1

File tree

6 files changed

+11
-5
lines changed

6 files changed

+11
-5
lines changed

myst_parser/_compat.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
"""Helpers for cross compatibility across dependency versions."""
2+
import sys
23
from typing import Callable, Iterable
34

45
from docutils.nodes import Element
56

7+
if sys.version_info >= (3, 8):
8+
from typing import Literal, Protocol, get_args, get_origin # noqa: F401
9+
else:
10+
from typing_extensions import Literal, Protocol, get_args, get_origin # noqa: F401
11+
612

713
def findall(node: Element) -> Callable[..., Iterable[Element]]:
814
"""Iterate through"""

myst_parser/_docs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
from sphinx.directives import other
1111
from sphinx.util import logging
1212
from sphinx.util.docutils import SphinxDirective
13-
from typing_extensions import get_args, get_origin
1413

14+
from ._compat import get_args, get_origin
1515
from .config.main import MdParserConfig
1616
from .parsers.docutils_ import Parser as DocutilsParser
1717

myst_parser/config/dc_validators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import dataclasses as dc
55
from typing import Any, Sequence
66

7-
from typing_extensions import Protocol
7+
from myst_parser._compat import Protocol
88

99

1010
def validate_field(inst: Any, field: dc.Field, value: Any) -> None:

myst_parser/parsers/docutils_.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
from docutils import frontend, nodes
66
from docutils.core import default_description, publish_cmdline
77
from docutils.parsers.rst import Parser as RstParser
8-
from typing_extensions import Literal, get_args, get_origin
98

9+
from myst_parser._compat import Literal, get_args, get_origin
1010
from myst_parser.config.main import (
1111
MdParserConfig,
1212
TopmatterReadError,

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ dependencies = [
4040
"mdit-py-plugins~=0.3.1",
4141
"pyyaml",
4242
"sphinx>=4,<6",
43-
"typing-extensions",
43+
'typing-extensions; python_version < "3.8"',
4444
]
4545

4646
[project.urls]

tests/test_docutils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
import pytest
66
from docutils import VersionInfo, __version_info__
7-
from typing_extensions import Literal
87

8+
from myst_parser._compat import Literal
99
from myst_parser.mdit_to_docutils.base import make_document
1010
from myst_parser.parsers.docutils_ import (
1111
Parser,

0 commit comments

Comments
 (0)