zulip_bots: Remove fallback code for Python < 3.5.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2021-03-04 15:41:08 -08:00
parent 56f4d3b2a8
commit f2e2f1c7ff
2 changed files with 8 additions and 21 deletions

View file

@ -1,12 +1,8 @@
from unittest.mock import patch
from unittest import skipIf
from sys import version_info
from importlib import import_module
from zulip_bots.test_lib import BotTestCase, DefaultTests
@skipIf(version_info[:2] < (3, 5), "monkeytestit requires python3.5+")
class TestMonkeyTestitBot(BotTestCase, DefaultTests):
bot_name = "monkeytestit"

View file

@ -1,4 +1,5 @@
import sys
import importlib
import importlib.util
import os
from typing import Any, Optional, Text, Tuple
from pathlib import Path
@ -6,25 +7,15 @@ from pathlib import Path
current_dir = os.path.dirname(os.path.abspath(__file__))
def import_module_from_source(path: Text, name: Text) -> Any:
# importlib.util.module_from_spec is supported from Python3.5
py_version = sys.version_info
if py_version.major < 3 or (py_version.major == 3 and py_version.minor < 5):
import imp
module = imp.load_source(name, path)
else:
import importlib.util
spec = importlib.util.spec_from_file_location(name, path)
module = importlib.util.module_from_spec(spec)
loader = spec.loader
if loader is None:
return None
loader.exec_module(module) # type: ignore # FIXME: typeshed issue?
spec = importlib.util.spec_from_file_location(name, path)
module = importlib.util.module_from_spec(spec)
loader = spec.loader
if loader is None:
return None
loader.exec_module(module) # type: ignore # FIXME: typeshed issue?
return module
def import_module_by_name(name: Text) -> Any:
import importlib
try:
return importlib.import_module(name)
except ImportError: