1515import sys
1616import warnings
1717from collections import defaultdict
18- from collections .abc import Iterable
18+ from collections .abc import Sequence
1919from pathlib import Path
2020from typing import Self , TextIO
2121
@@ -129,11 +129,11 @@ def average_coverage(
129129 if len (platforms ) == 0 :
130130 return float ("nan" )
131131
132- total = sum ([coverage (setmap , [ p ] ) for p in platforms ])
132+ total = sum ([coverage (setmap , { p } ) for p in platforms ])
133133 return total / len (platforms )
134134
135135
136- def distance (setmap , p1 , p2 ):
136+ def distance (setmap , p1 , p2 ) -> float :
137137 """
138138 Compute distance between two platforms
139139 """
@@ -148,14 +148,14 @@ def distance(setmap, p1, p2):
148148 return d
149149
150150
151- def divergence (setmap ):
151+ def divergence (setmap ) -> float :
152152 """
153153 Compute code divergence as defined by Harrell and Kitson
154154 i.e. average of pair-wise distances between platform sets
155155 """
156156 platforms = extract_platforms (setmap )
157157
158- d = 0
158+ d = 0.0
159159 npairs = 0
160160 for p1 , p2 in it .combinations (platforms , 2 ):
161161 d += distance (setmap , p1 , p2 )
@@ -166,14 +166,14 @@ def divergence(setmap):
166166 return d / float (npairs )
167167
168168
169- def summary (setmap : defaultdict [ str , int ], stream : TextIO = sys .stdout ):
169+ def summary (setmap : dict [ frozenset [ str ] , int ], stream : TextIO = sys .stdout ):
170170 """
171171 Produce a summary report for the platform set, including
172172 a breakdown of SLOC per platform subset, code divergence, etc.
173173
174174 Parameters
175175 ----------
176- setmap: defaultdict[ str, int]
176+ setmap: dict[frozenset[ str] , int]
177177 The setmap used to compute the summary report.
178178
179179 stream: TextIO, default: sys.stdout
@@ -214,7 +214,7 @@ def summary(setmap: defaultdict[str, int], stream: TextIO = sys.stdout):
214214
215215def clustering (
216216 output_name : str ,
217- setmap : defaultdict [ str , int ],
217+ setmap : dict [ frozenset [ str ] , int ],
218218 stream : TextIO = sys .stdout ,
219219):
220220 """
@@ -225,7 +225,7 @@ def clustering(
225225 output_name: str
226226 The filename for the dendrogram.
227227
228- setmap: defaultdict[ str, int]
228+ setmap: dict[frozenset[ str] , int]
229229 The setmap used to compute the clustering statistics.
230230
231231 stream: TextIO, default: sys.stdout
@@ -313,7 +313,7 @@ def find_duplicates(codebase: CodeBase) -> list[set[Path]]:
313313 A list of all sets of Paths with identical contents.
314314 """
315315 # Search for possible matches using a hash, ignoring symlinks.
316- possible_matches = {}
316+ possible_matches : dict [ str , set ] = {}
317317 for path in codebase :
318318 path = Path (path )
319319 if path .is_symlink ():
@@ -486,15 +486,15 @@ def is_symlink(self):
486486 def _platforms_str (
487487 self ,
488488 all_platforms : set [str ],
489- labels : Iterable [str ] = string .ascii_uppercase ,
489+ labels : Sequence [str ] = string .ascii_uppercase ,
490490 ) -> str :
491491 """
492492 Parameters
493493 ----------
494494 all_platforms: set[str]
495495 The set of all platforms.
496496
497- labels: Iterable [str], default: string.ascii_uppercase
497+ labels: Sequence [str], default: string.ascii_uppercase
498498 The labels to use in place of real platform names.
499499
500500 Returns
@@ -605,7 +605,7 @@ def __init__(self, rootdir: str | os.PathLike[str]):
605605 def insert (
606606 self ,
607607 filename : str | os .PathLike [str ],
608- setmap : defaultdict [ str , int ],
608+ setmap : dict [ frozenset [ str ] , int ],
609609 ):
610610 """
611611 Insert a new file into the tree, creating as many nodes as necessary.
@@ -653,7 +653,7 @@ def _print(
653653 prefix : str = "" ,
654654 connector : str = "" ,
655655 fancy : bool = True ,
656- levels : int = None ,
656+ levels : int | None = None ,
657657 ):
658658 """
659659 Recursive helper function to print all nodes in a FileTree.
@@ -740,7 +740,7 @@ def _print(
740740
741741 return lines
742742
743- def write_to (self , stream : TextIO , levels : int = None ):
743+ def write_to (self , stream : TextIO , levels : int | None = None ):
744744 """
745745 Write the FileTree to the specified stream.
746746
@@ -766,7 +766,7 @@ def files(
766766 * ,
767767 stream : TextIO = sys .stdout ,
768768 prune : bool = False ,
769- levels : int = None ,
769+ levels : int | None = None ,
770770):
771771 """
772772 Produce a file tree representing the code base.
@@ -796,7 +796,7 @@ def files(
796796 # Build up a tree from the list of files.
797797 tree = FileTree (codebase .directories [0 ])
798798 for f in codebase :
799- setmap = defaultdict (int )
799+ setmap : dict [ frozenset [ str ], int ] = defaultdict (int )
800800 if state :
801801 association = state .get_map (f )
802802 for node in filter (
@@ -828,10 +828,10 @@ def files(
828828 ]
829829 legend += ["[" + " | " .join (header ) + "]" ]
830830 legend += ["" ]
831- legend = "\n " .join (legend )
831+ legend_string = "\n " .join (legend )
832832 if not stream .isatty ():
833- legend = _strip_colors (legend )
834- print (legend , file = stream )
833+ legend_string = _strip_colors (legend_string )
834+ print (legend_string , file = stream )
835835
836836 # Print the tree.
837837 tree .write_to (stream , levels = levels )
0 commit comments