File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 99import tempfile
1010from contextlib import suppress
1111from datetime import datetime , timezone
12+ from functools import cached_property
1213from importlib .util import find_spec
1314from pathlib import Path
1415from typing import TYPE_CHECKING , ClassVar , cast
@@ -90,13 +91,17 @@ def __init__(
9091 """Whether to force inspecting (importing) modules, even when sources were found."""
9192 self .store_source : bool = store_source
9293 """Whether to store source code in the lines collection."""
93- self .finder : ModuleFinder = ModuleFinder (search_paths )
94- """The module source finder."""
94+ self ._search_paths : Sequence [str | Path ] | None = search_paths
9595 self ._time_stats : dict = {
9696 "time_spent_visiting" : 0 ,
9797 "time_spent_inspecting" : 0 ,
9898 }
9999
100+ @cached_property
101+ def finder (self ) -> ModuleFinder :
102+ """The module source finder."""
103+ return ModuleFinder (search_paths = self ._search_paths )
104+
100105 def load (
101106 self ,
102107 objspec : str | Path | None = None ,
Original file line number Diff line number Diff line change @@ -519,3 +519,14 @@ def test_loading_utf8_with_bom_files(tmp_path: Path) -> None:
519519 loader = GriffeLoader (search_paths = [tmp_path ])
520520 package = loader .load ("pkg" )
521521 assert "func" in package .members # Just checking all went well, no SyntaxError exceptions raised.
522+
523+
524+ def test_deferred_finder (tmp_path : Path ) -> None :
525+ """Check that the deferred finder works as expected."""
526+ ns = tmp_path / "ns"
527+ l1 = GriffeLoader (search_paths = [tmp_path ])
528+ ns .mkdir (exist_ok = False )
529+ l2 = GriffeLoader (search_paths = [tmp_path ])
530+ l1_result = l1 .load ("ns" )
531+ l2_result = l2 .load ("ns" )
532+ assert l1_result .as_dict () == l2_result .as_dict ()
You can’t perform that action at this time.
0 commit comments