From b9bd63b64cee19993c30f0a2a4a8494ed711b6f5 Mon Sep 17 00:00:00 2001 From: Mark Nottingham Date: Tue, 30 Jan 2024 15:26:03 +1100 Subject: [PATCH] Changed: Don't lazy-load field parser modules. --- httplint/field/finder.py | 7 ++++--- httplint/field/parsers/__init__.py | 9 ++++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/httplint/field/finder.py b/httplint/field/finder.py index 63dcc21..539bf00 100644 --- a/httplint/field/finder.py +++ b/httplint/field/finder.py @@ -1,4 +1,3 @@ -import importlib import sys from typing import ( @@ -82,9 +81,8 @@ def find_module(field_name: str) -> Any: name_token = HttpFieldFinder.field_aliases[name_token] try: module_name = f"httplint.field.parsers.{name_token}" - importlib.import_module(module_name) return sys.modules[module_name] - except (ImportError, KeyError, TypeError): + except (KeyError, TypeError): return None @staticmethod @@ -111,3 +109,6 @@ def parse(self, field_value: str, add_note: AddNoteMethodType) -> Any: def evaluate(self, add_note: AddNoteMethodType) -> None: return + + +import httplint.field.parsers # pylint: disable=wrong-import-position,unused-import diff --git a/httplint/field/parsers/__init__.py b/httplint/field/parsers/__init__.py index 94456ab..045c7b2 100644 --- a/httplint/field/parsers/__init__.py +++ b/httplint/field/parsers/__init__.py @@ -1 +1,8 @@ -# intentionally left blank +import importlib +import pkgutil + +__path__ = pkgutil.extend_path(__path__, __name__) +for imp, module, ispackage in pkgutil.walk_packages( + path=__path__, prefix=f"{__name__}." +): + importlib.import_module(module)