From f2e2f1c7ffc49642a4d7eac4e54aebba606704da Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Thu, 4 Mar 2021 15:41:08 -0800 Subject: [PATCH] zulip_bots: Remove fallback code for Python < 3.5. Signed-off-by: Anders Kaseorg --- .../bots/monkeytestit/test_monkeytestit.py | 4 --- zulip_bots/zulip_bots/finder.py | 25 ++++++------------- 2 files changed, 8 insertions(+), 21 deletions(-) diff --git a/zulip_bots/zulip_bots/bots/monkeytestit/test_monkeytestit.py b/zulip_bots/zulip_bots/bots/monkeytestit/test_monkeytestit.py index b1f79b6..c4b53b7 100644 --- a/zulip_bots/zulip_bots/bots/monkeytestit/test_monkeytestit.py +++ b/zulip_bots/zulip_bots/bots/monkeytestit/test_monkeytestit.py @@ -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" diff --git a/zulip_bots/zulip_bots/finder.py b/zulip_bots/zulip_bots/finder.py index 14c14f5..ec6d758 100644 --- a/zulip_bots/zulip_bots/finder.py +++ b/zulip_bots/zulip_bots/finder.py @@ -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: