Skip to content

mypy_test.py: Use pathlib more - #8680

Merged
AlexWaygood merged 3 commits into
masterfrom
mypytest-pathlib
Sep 5, 2022
Merged

AlexWaygood merged 3 commits into
masterfrom
mypytest-pathlib

Conversation

@AlexWaygood

Copy link
Copy Markdown
Member

No description provided.

Comment thread tests/mypy_test.py Resolved
Comment thread tests/mypy_test.py Resolved
Comment thread tests/mypy_test.py Outdated
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):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can replace this whole loop with something using full.glob("**/*.{py,pyi}").

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

Comment thread tests/mypy_test.py
files.append(module)
seen.add(module.stem)
else:
to_add = sorted(module.rglob("*.pyi"))

@JelleZijlstra JelleZijlstra Sep 4, 2022 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you need **/*.pyi; the current code will not recurse into subdirectories.

@AlexWaygood AlexWaygood Sep 4, 2022 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for confirming!

@srittau

srittau commented Sep 5, 2022

Copy link
Copy Markdown
Collaborator

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.

@AlexWaygood
AlexWaygood merged commit b6d28ac into master Sep 5, 2022
@AlexWaygood
AlexWaygood deleted the mypytest-pathlib branch September 5, 2022 13:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants