Skip to content

Commit 83711c6

Browse files
committed
Use os functions only when necessary. Update comments.
1 parent 0b6da96 commit 83711c6

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

reccmp/dir.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ def resolve_cvdump(self, path_str: str) -> str:
134134
return self._memo[path_str]
135135

136136

137-
def is_file_c_like(filename: str) -> bool:
138-
(_, ext) = os.path.splitext(filename)
139-
return ext.lower() in (
137+
def is_file_c_like(path: Path) -> bool:
138+
"""Tests the given path for typical C/C++ file extensions."""
139+
return path.suffix.lower() in (
140140
".c",
141141
".h",
142142
".cc",
@@ -160,13 +160,14 @@ def platform_independent_path_sort(paths: Iterable[Path]) -> Iterator[Path]:
160160

161161

162162
def walk_source_dir(source: Path, *, recursive: bool = True) -> Iterator[Path]:
163-
"""Generator to walk the given directory recursively and return
164-
any C++ files found."""
163+
"""Returns any C/C++ source code files found in the given directory tree."""
165164

165+
# Python 3.12 introduced Path.walk(). We use os.walk() instead for broader compatibility.
166166
for subdir, _, files in os.walk(source.absolute()):
167167
for file in files:
168-
if is_file_c_like(file):
169-
yield Path(os.path.join(subdir, file))
168+
path = Path(os.path.join(subdir, file))
169+
if is_file_c_like(path):
170+
yield path
170171

171172
if not recursive:
172173
break
@@ -186,7 +187,7 @@ def source_code_search(search_paths: Path | Iterable[Path]) -> Iterator[Path]:
186187
if not path.exists():
187188
continue
188189

189-
if path.is_file() and is_file_c_like(path.name):
190+
if path.is_file() and is_file_c_like(path):
190191
code_files.add(path)
191192
continue
192193

0 commit comments

Comments
 (0)