Skip to content

Commit d3890ce

Browse files
fix(parser): preserve lazy export introspection
1 parent 2bfc897 commit d3890ce

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

‎aws_lambda_powertools/utilities/parser/__init__.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ def __getattr__(name: str) -> object:
2727
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
2828

2929

30+
def __dir__() -> list[str]:
31+
return sorted(set(globals()) | set(__all__))
32+
33+
3034
__all__ = [
3135
"event_parser",
3236
"parse",

‎tests/functional/parser/test_parser.py‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,3 +386,26 @@ def test_parser_import_does_not_eagerly_load_envelopes():
386386
check=False,
387387
)
388388
assert result.returncode == 0, f"import * test failed:\n{result.stderr}\n{result.stdout}"
389+
390+
391+
def test_parser_lazy_exports_are_discoverable():
392+
"""Lazy exports must remain discoverable through standard module introspection."""
393+
import subprocess
394+
import sys
395+
396+
script = """
397+
import inspect
398+
import sys
399+
import aws_lambda_powertools.utilities.parser as parser
400+
401+
assert "envelopes" in dir(parser)
402+
assert "BaseEnvelope" in dir(parser)
403+
assert "aws_lambda_powertools.utilities.parser.envelopes" not in sys.modules
404+
405+
members = dict(inspect.getmembers(parser))
406+
assert members["envelopes"] is parser.envelopes
407+
assert members["BaseEnvelope"] is parser.BaseEnvelope
408+
"""
409+
410+
result = subprocess.run([sys.executable, "-c", script], capture_output=True, text=True, check=False)
411+
assert result.returncode == 0, f"parser introspection test failed:\n{result.stderr}\n{result.stdout}"

0 commit comments

Comments
 (0)