Thanks to visit codestin.com
Credit goes to github.com

Skip to content

pytype_test: support either slashes in path params #13943

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

Conversation

Avasam
Copy link
Collaborator

@Avasam Avasam commented May 4, 2025

Extracted from #13795

Fixes #13936

Removes all usages of os.path.sep

Alternatively: use os.path.normpath. But I went the pathlib route.

Comment on lines 97 to 106
def _get_relative(filename: str) -> str:
top = 0
def _get_relative(filename: StrPath) -> Path:
filepath = Path(filename)
for d in TYPESHED_SUBDIRS:
try:
top = filename.index(d + os.path.sep)
return filepath.relative_to(Path(d).absolute().parent)
except ValueError:
continue
else:
break
return filename[top:]
raise ValueError(f"{filepath} not relative to {TYPESHED_SUBDIRS}")
Copy link
Collaborator Author

@Avasam Avasam May 4, 2025

Choose a reason for hiding this comment

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

Could we just do instead:

def _get_relative(filename: StrPath) -> Path:
    return Path(filename).absolute().relative_to(TS_BASE_PATH.absolute())

Which makes _get_relative viable to be renamed relative_to_ts_base and moved to ts_utils/paths.py

Copy link
Collaborator

Choose a reason for hiding this comment

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

We could also review/refactor the callers of _get_relative() to pass a Path to _get_relative(). I'm not even sure we need to call _get_relative() in all places it's used at the moment.

@srittau srittau merged commit 8d4cafd into python:main May 5, 2025
58 checks passed
@Avasam Avasam deleted the pytype_test-support-either-slashes-in-path-params branch May 5, 2025 13:23
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.

Running "tests/runtests.py" on Windows
2 participants