Skip to content

Commit 8636323

Browse files
committed
Install typing_extensions if needed
The `typing_extensions` module was imported but not listed as a requirement, so importing `daidepp` failed if `typing_extensions` wasn't installed for another reason. I have added it as an explicit requirement and only use it if `Literal` or `get_args` cannot be imported directly from the `typing` module.
1 parent 30462c5 commit 8636323

File tree

7 files changed

+30
-7
lines changed

7 files changed

+30
-7
lines changed

setup.cfg

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ python_requires = >=3.7
1515
install_requires =
1616
parsimonious==0.9.0
1717
importlib-metadata>=1.4.0 ; python_version < "3.8"
18+
typing_extensions>=3.10.0.0 ; python_version < "3.8"
1819

1920
[options.packages.find]
2021
where = src

src/daidepp/constants.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
from typing_extensions import Literal
1+
try:
2+
from typing import Literal
3+
except ImportError:
4+
from typing_extensions import Literal
25

36
Power = Literal["AUS", "ENG", "FRA", "GER", "ITA", "RUS", "TUR"]
47
UnitType = Literal["AMY", "FLT"]

src/daidepp/grammar/grammar.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@
55
from __future__ import annotations
66

77
from typing import Dict, Tuple
8-
from typing_extensions import get_args
98

10-
from typing_extensions import Literal
9+
try:
10+
from typing import Literal
11+
from typing import get_args
12+
except ImportError:
13+
from typing_extensions import Literal
14+
from typing_extensions import get_args
1115

1216
DAIDELevel = Literal[
1317
0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160

src/daidepp/grammar/grammar_utils.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
from typing import Dict, List, Optional, Set, Tuple, Union
44

55
from parsimonious.grammar import Grammar
6-
from typing_extensions import Literal
6+
7+
try:
8+
from typing import Literal
9+
except ImportError:
10+
from typing_extensions import Literal
711

812
from daidepp.constants import PressKeywords
913
from daidepp.grammar.grammar import (

src/daidepp/keywords/base_keywords.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
from dataclasses import dataclass
44
from typing import Optional, Tuple, Union
55

6-
from typing_extensions import get_args
6+
try:
7+
from typing import get_args
8+
except ImportError:
9+
from typing_extensions import get_args
710

811
from daidepp.constants import *
912
from daidepp.keywords.daide_object import _DAIDEObject

src/daidepp/visitor.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
from typing import Any
33

44
from parsimonious.nodes import Node, NodeVisitor
5-
from typing_extensions import get_args
5+
6+
try:
7+
from typing import get_args
8+
except ImportError:
9+
from typing_extensions import get_args
610

711
from daidepp.constants import ProvinceNoCoast
812
from daidepp.keywords.base_keywords import *

tests/conftest.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import pytest
2-
from typing_extensions import get_args
2+
3+
try:
4+
from typing import get_args
5+
except ImportError:
6+
from typing_extensions import get_args
37

48
from daidepp.grammar import create_daide_grammar
59
from daidepp.grammar.grammar import DAIDELevel, MAX_DAIDE_LEVEL

0 commit comments

Comments
 (0)