11from __future__ import annotations
2- from typing import List , Optional , Sequence , Set , Tuple , TypedDict
2+ from typing import TypedDict
3+ from collections .abc import Sequence
34from grimp .domain .analysis import PackageDependency , Route
45from grimp .domain .valueobjects import Layer
56from grimp import _rustgrimp as rust # type: ignore[attr-defined]
@@ -18,7 +19,7 @@ class Import(TypedDict):
1819
1920# Corresponds to importer, imported.
2021# Prefer this form to Import, as it's both more lightweight, and hashable.
21- ImportTuple = Tuple [str , str ]
22+ ImportTuple = tuple [str , str ]
2223
2324
2425class DetailedImport (Import ):
@@ -33,22 +34,22 @@ class ImportGraph:
3334
3435 def __init__ (self ) -> None :
3536 super ().__init__ ()
36- self ._cached_modules : Set [str ] | None = None
37+ self ._cached_modules : set [str ] | None = None
3738 self ._rustgraph = rust .Graph ()
3839
3940 # Mechanics
4041 # ---------
4142
4243 @property
43- def modules (self ) -> Set [str ]:
44+ def modules (self ) -> set [str ]:
4445 """
4546 The names of all the modules in the graph.
4647 """
4748 if self ._cached_modules is None :
4849 self ._cached_modules = self ._rustgraph .get_modules ()
4950 return self ._cached_modules
5051
51- def find_matching_modules (self , expression : str ) -> Set [str ]:
52+ def find_matching_modules (self , expression : str ) -> set [str ]:
5253 """
5354 Find all modules matching the passed expression.
5455
@@ -135,8 +136,8 @@ def add_import(
135136 * ,
136137 importer : str ,
137138 imported : str ,
138- line_number : Optional [ int ] = None ,
139- line_contents : Optional [ str ] = None ,
139+ line_number : int | None = None ,
140+ line_contents : str | None = None ,
140141 ) -> None :
141142 """
142143 Add a direct import between two modules to the graph. If the modules are not already
@@ -166,7 +167,7 @@ def count_imports(self) -> int:
166167 # Descendants
167168 # -----------
168169
169- def find_children (self , module : str ) -> Set [str ]:
170+ def find_children (self , module : str ) -> set [str ]:
170171 """
171172 Find all modules one level below the module. For example, the children of
172173 foo.bar might be foo.bar.one and foo.bar.two, but not foo.bar.two.green.
@@ -180,7 +181,7 @@ def find_children(self, module: str) -> Set[str]:
180181 raise ValueError ("Cannot find children of a squashed module." )
181182 return self ._rustgraph .find_children (module )
182183
183- def find_descendants (self , module : str ) -> Set [str ]:
184+ def find_descendants (self , module : str ) -> set [str ]:
184185 """
185186 Find all modules below the module. For example, the descendants of
186187 foo.bar might be foo.bar.one and foo.bar.two and foo.bar.two.green.
@@ -213,16 +214,16 @@ def direct_import_exists(
213214 importer = importer , imported = imported , as_packages = as_packages
214215 )
215216
216- def find_modules_directly_imported_by (self , module : str ) -> Set [str ]:
217+ def find_modules_directly_imported_by (self , module : str ) -> set [str ]:
217218 return self ._rustgraph .find_modules_directly_imported_by (module )
218219
219- def find_modules_that_directly_import (self , module : str ) -> Set [str ]:
220+ def find_modules_that_directly_import (self , module : str ) -> set [str ]:
220221 if self ._rustgraph .contains_module (module ):
221222 # TODO panics if module isn't in modules.
222223 return self ._rustgraph .find_modules_that_directly_import (module )
223224 return set ()
224225
225- def get_import_details (self , * , importer : str , imported : str ) -> List [DetailedImport ]:
226+ def get_import_details (self , * , importer : str , imported : str ) -> list [DetailedImport ]:
226227 """
227228 Return available metadata relating to the direct imports between two modules, in the form:
228229 [
@@ -246,7 +247,7 @@ def get_import_details(self, *, importer: str, imported: str) -> List[DetailedIm
246247 imported = imported ,
247248 )
248249
249- def find_matching_direct_imports (self , import_expression : str ) -> List [Import ]:
250+ def find_matching_direct_imports (self , import_expression : str ) -> list [Import ]:
250251 """
251252 Find all direct imports matching the passed expressions.
252253
@@ -290,7 +291,7 @@ def find_matching_direct_imports(self, import_expression: str) -> List[Import]:
290291 # Indirect imports
291292 # ----------------
292293
293- def find_downstream_modules (self , module : str , as_package : bool = False ) -> Set [str ]:
294+ def find_downstream_modules (self , module : str , as_package : bool = False ) -> set [str ]:
294295 """
295296 Return a set of the names of all the modules that import (even indirectly) the
296297 supplied module name.
@@ -312,7 +313,7 @@ def find_downstream_modules(self, module: str, as_package: bool = False) -> Set[
312313 """
313314 return self ._rustgraph .find_downstream_modules (module , as_package )
314315
315- def find_upstream_modules (self , module : str , as_package : bool = False ) -> Set [str ]:
316+ def find_upstream_modules (self , module : str , as_package : bool = False ) -> set [str ]:
316317 """
317318 Return a set of the names of all the modules that are imported (even indirectly) by the
318319 supplied module.
@@ -352,7 +353,7 @@ def find_shortest_chain(
352353
353354 def find_shortest_chains (
354355 self , importer : str , imported : str , as_packages : bool = True
355- ) -> Set [ Tuple [str , ...]]:
356+ ) -> set [ tuple [str , ...]]:
356357 """
357358 Find the shortest import chains that exist between the importer and imported, and
358359 between any modules contained within them if as_packages is True. Only one chain per
@@ -474,7 +475,7 @@ def __repr__(self) -> str:
474475 stringified_modules = "empty"
475476 return f"<{ self .__class__ .__name__ } : { stringified_modules } >"
476477
477- def __deepcopy__ (self , memodict : dict ) -> " ImportGraph" :
478+ def __deepcopy__ (self , memodict : dict ) -> ImportGraph :
478479 new_graph = ImportGraph ()
479480 new_graph ._rustgraph = self ._rustgraph .clone ()
480481 return new_graph
0 commit comments