Repository navigation
mypy_test.py: Use pathlib more - #8680
Conversation
| files.append(full) | ||
| elif os.path.isfile(os.path.join(full, "__init__.pyi")) or os.path.isfile(os.path.join(full, "__init__.py")): | ||
| elif (full / "__init__.pyi").is_file() or (full / "__init__.py").is_file(): | ||
| for r, ds, fs in os.walk(full): |
There was a problem hiding this comment.
Maybe we can replace this whole loop with something using full.glob("**/*.{py,pyi}").
There was a problem hiding this comment.
I'm... actually not quite sure why we're collecting .py files here anyway. This part of mypy_test.py should probably only care about .pyi files!
| files.append(module) | ||
| seen.add(module.stem) | ||
| else: | ||
| to_add = sorted(module.rglob("*.pyi")) |
There was a problem hiding this comment.
I believe you need **/*.pyi; the current code will not recurse into subdirectories.
There was a problem hiding this comment.
I think it will recurse, because we're using rglob, not glob :) https://docs.python.org/3/library/pathlib.html#pathlib.Path.rglob
I checked locally, and it collects the same number of files (for both the stdlib and the third-party packages) as we currently do in CI
There was a problem hiding this comment.
I did some more testing -- I'm pretty confident that the code proposed in this PR collects exactly the same list of files as the code on typeshed master. The order of the files list appears to be slightly different, but personally I don't think that matters much?
|
Not a review, but +1 on using pathlib here. I had the same thought when looking at the previous PR. This also makes it more clear where a "path" is used and where a "path-like string" is used. |
No description provided.