Skip to content

Bugfix/fix failing tests on windows due to relpath #8094

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
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ This submodule contains types for the Python standard library.

Due to the way git submodules work, you'll have to do
```
git submodule update typeshed
git submodule update mypy/typeshed
Copy link
Contributor Author

Choose a reason for hiding this comment

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

By accident I saw that the original command did not work.

```
whenever you change branches, merge, rebase, or pull.

Expand Down
14 changes: 12 additions & 2 deletions mypy/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,12 @@ def on_file(self,
type_map: Dict[Expression, Type],
options: Options) -> None:
self.last_xml = None
path = os.path.relpath(tree.path)

try:
path = os.path.relpath(tree.path)
except ValueError:
return

if should_skip_path(path):
return

Expand Down Expand Up @@ -813,7 +818,12 @@ def on_file(self,
modules: Dict[str, MypyFile],
type_map: Dict[Expression, Type],
options: Options) -> None:
path = os.path.relpath(tree.path)

try:
path = os.path.relpath(tree.path)
except ValueError:
return

Copy link
Contributor Author

@Netzeband Netzeband Dec 5, 2019

Choose a reason for hiding this comment

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

What is the semantic reason for making the path relative? When I understand the code correctly a relative path outside of the directory where the code-under-check is in, should be ignored anyway (see should_skip_path case ...)?
So a final solution could be to simply return from this function in case of a ValueError? Or to mark the resulting path as invalid and skip it with should_skip_path. What do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

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

We use relative paths since the paths could be included in the output and we want the output to be tidy and not depend on the current working directory. I agree that if we can't determine a relative path, we can just skip and return (both here and above).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I solved it by returning directly from the exception handler. Another alternative would be to mark the path as invalid (None or empty string for example) and skip then from the function should_skip_path(...). However this would introduce special state for path, which is not obvious, especially in cases where the function should_skip_path(...) is not used (in future). On the other hand with the current solution there are two logics to skip: the official one from should_skip_path(...) and the new one from the exception handler.
Just decide by yourself, which solution you like more. I can change it another time, if you want.

if should_skip_path(path):
return

Expand Down
4 changes: 3 additions & 1 deletion test-data/unit/check-incremental.test
Original file line number Diff line number Diff line change
Expand Up @@ -4117,7 +4117,9 @@ class C:
[out2]
main:5: error: Incompatible types in assignment (expression has type "str", variable has type "int")

[case testBazelFlagIgnoresFileChanges]
[case testBazelFlagIgnoresFileChanges-skip]
-- This test fails on windows, when the mypy source in on a different drive than
-- the run-directory. In this case os.path.relpath(...) fails with an exception
-- Since the initial run wrote a cache file, the second run ignores the source
# flags: --bazel
from a import f
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy