Skip to content

Commit

Permalink
Changed: Don't lazy-load field parser modules.
Browse files Browse the repository at this point in the history
  • Loading branch information
mnot committed Jan 30, 2024
1 parent fe76356 commit b9bd63b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
7 changes: 4 additions & 3 deletions httplint/field/finder.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import importlib
import sys

from typing import (
Expand Down Expand Up @@ -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
Expand All @@ -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
9 changes: 8 additions & 1 deletion httplint/field/parsers/__init__.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit b9bd63b

Please sign in to comment.