File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -177,10 +177,31 @@ def all_py_files_in_source_are_in_py_typed_dirs(source: zipfile.ZipFile | tarfil
177177 all_python_files : list [Path ] = []
178178 py_file_suffixes = {".py" , ".pyi" }
179179
180+ # Obtain an iterator over all files in the zipfile/tarfile.
181+ # Filter out empty __init__.py files: this reduces false negatives
182+ # in cases like this:
183+ #
184+ # repo_root/
185+ # ├─ src/
186+ # | ├─ pkg/
187+ # | | ├─ __init__.py <-- This file is empty
188+ # | | ├─ subpkg/
189+ # | | | ├─ __init__.py
190+ # | | | ├─ libraryfile.py
191+ # | | | ├─ libraryfile2.py
192+ # | | | ├─ py.typed
180193 if isinstance (source , zipfile .ZipFile ):
181- path_iter = (Path (zip_info .filename ) for zip_info in source .infolist () if not zip_info .is_dir ())
194+ path_iter = (
195+ Path (zip_info .filename )
196+ for zip_info in source .infolist ()
197+ if ((not zip_info .is_dir ()) and not (Path (zip_info .filename ).name == "__init__.py" and zip_info .file_size == 0 ))
198+ )
182199 else :
183- path_iter = (Path (tar_info .path ) for tar_info in source if tar_info .isfile ())
200+ path_iter = (
201+ Path (tar_info .path )
202+ for tar_info in source
203+ if (tar_info .isfile () and not (Path (tar_info .name ).name == "__init__.py" and tar_info .size == 0 ))
204+ )
184205
185206 for path in path_iter :
186207 if path .suffix in py_file_suffixes :
You can’t perform that action at this time.
0 commit comments