Skip to content

Fix --custom-typeshed-dir crash caused by #13155 #13296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ def __init__(
if options.custom_typeshed_dir is not None:
# Check if module lives under custom_typeshed_dir subtree
custom_typeshed_dir = os.path.abspath(options.custom_typeshed_dir)
path = os.path.abspath(path)
if os.path.commonpath((path, custom_typeshed_dir)) == custom_typeshed_dir:
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe it still can through ValueError on Windows if path and custom_typeshed_dir live on different drives.

Copy link
Member Author

@AlexWaygood AlexWaygood Aug 1, 2022

Choose a reason for hiding this comment

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

Good point (though I'm tempted to say that anybody trying to do that deserves what they're getting!)

continue

Expand Down
13 changes: 13 additions & 0 deletions test-data/unit/cmdline.test
Original file line number Diff line number Diff line change
Expand Up @@ -1465,3 +1465,16 @@ sys.path = path
mypy: "typing.py" shadows library module "typing"
note: A user-defined top-level module with name "typing" is not supported
== Return code: 2

[case testCustomTypeshedDirWithRelativePathDoesNotCrash]
# cmd: mypy --custom-typeshed-dir dir dir/typing.pyi
[file dir/stdlib/abc.pyi]
[file dir/stdlib/builtins.pyi]
[file dir/stdlib/sys.pyi]
[file dir/stdlib/types.pyi]
[file dir/stdlib/typing.pyi]
[file dir/stdlib/typing_extensions.pyi]
[file dir/stdlib/VERSIONS]
[out]
Failed to find builtin module mypy_extensions, perhaps typeshed is broken?
== Return code: 2