Commit cb120bf4

Michal Vasilek <michal@vasilek.cz>
2022-12-22 04:46:28
Fix mypy (#158)
mypy doesn't correctly handle try except blocks, so it's necessary to import from the correct module based on the python version.
1 parent 528a5ba
Changed files (1)
openai/api_requestor.py
@@ -1,5 +1,6 @@
 import json
 import platform
+import sys
 import threading
 import warnings
 from json import JSONDecodeError
@@ -8,10 +9,9 @@ from urllib.parse import urlencode, urlsplit, urlunsplit
 
 import requests
 
-# Literal is available from Python 3.8
-try:
+if sys.version_info >= (3, 8):
     from typing import Literal
-except ImportError:
+else:
     from typing_extensions import Literal
 
 import openai