Skip to content

Commit e175aa6

Browse files
committed
Use Protocol from typing_extensions for pre-3.8 Python
This commit adds an extra dependency to PySTAC when installed in environments with versions of Python before 3.8. The 'Protocol' class in `typing` was made available in the core module as of 3.8, but previous versions can use it from the `typing_extensions` package. setup.py is changed to install typing_extensions for pre-3.8 versions, and a conditional import is used to import the Protocol class from the correct package.
1 parent 4c76a2b commit e175aa6

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

pystac/summaries.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import sys
12
import json
23
import numbers
34
import urllib.request
@@ -17,10 +18,14 @@
1718
cast,
1819
TypeVar,
1920
Iterable,
20-
Protocol,
2121
TYPE_CHECKING,
2222
)
2323

24+
if sys.version_info >= (3, 8):
25+
from typing import Protocol
26+
else:
27+
from typing_extensions import Protocol
28+
2429
if TYPE_CHECKING:
2530
from pystac.item import Item as Item_Type
2631
from pystac.collection import Collection as Collection_Type

setup.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@
2727
packages=find_packages(),
2828
py_modules=[splitext(basename(path))[0] for path in glob('pystac/*.py')],
2929
include_package_data=False,
30-
install_requires=["python-dateutil>=2.7.0"],
30+
install_requires=[
31+
"python-dateutil>=2.7.0",
32+
'typing_extensions >= 3.7; python_version < "3.8"',
33+
],
3134
extras_require={
3235
"validation": ["jsonschema>=3.0"],
3336
"orjson": ["orjson>=3.5"]

0 commit comments

Comments
 (0)