Skip to content

Commit 51ebc86

Browse files
committed
Add a typing compat module to avoid a dependency on typing-extensions for Py >= 3.8
1 parent f3f9e42 commit 51ebc86

File tree

8 files changed

+40
-7
lines changed

8 files changed

+40
-7
lines changed

bpython/_typing_compat.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# The MIT License
2+
#
3+
# Copyright (c) 2021 Sebastian Ramacher
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in
13+
# all copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
# THE SOFTWARE.
22+
23+
try:
24+
# introduced in Python 3.8
25+
from typing import Literal
26+
except ImportError:
27+
from typing_extensions import Literal # type: ignore
28+
29+
try:
30+
# introduced in Python 3.8
31+
from typing import Protocol
32+
except ImportError:
33+
from typing_extensions import Protocol # type: ignore

bpython/curtsies.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
Tuple,
3434
Union,
3535
)
36-
from typing_extensions import Protocol
36+
from ._typing_compat import Protocol
3737

3838
logger = logging.getLogger(__name__)
3939

bpython/curtsiesfrontend/_internal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import pydoc
2424
from types import TracebackType
2525
from typing import Optional, Type
26-
from typing_extensions import Literal
26+
from .._typing_compat import Literal
2727

2828
from .. import _internal
2929

bpython/curtsiesfrontend/repl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from enum import Enum
1515
from types import TracebackType
1616
from typing import Dict, Any, List, Optional, Tuple, Union, cast, Type
17-
from typing_extensions import Literal
17+
from .._typing_compat import Literal
1818

1919
import blessings
2020
import greenlet

bpython/filelock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# THE SOFTWARE.
2222

2323
from typing import Optional, Type, IO
24-
from typing_extensions import Literal
24+
from ._typing_compat import Literal
2525
from types import TracebackType
2626

2727
has_fcntl = True

bpython/inspection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from collections import namedtuple
2929
from typing import Any, Optional, Type
3030
from types import MemberDescriptorType, TracebackType
31-
from typing_extensions import Literal
31+
from ._typing_compat import Literal
3232

3333
from pygments.token import Token
3434
from pygments.lexers import Python3Lexer

bpython/repl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
from pathlib import Path
3939
from types import ModuleType, TracebackType
4040
from typing import cast, Tuple, Any, Optional, Type
41-
from typing_extensions import Literal
41+
from ._typing_compat import Literal
4242

4343
from pygments.lexers import Python3Lexer
4444
from pygments.token import Token

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ install_requires =
2727
pygments
2828
pyxdg
2929
requests
30-
typing-extensions
30+
typing-extensions; python_version < "3.8"
3131

3232
[options.extras_require]
3333
clipboard = pyperclip

0 commit comments

Comments
 (0)