pytype_test: support either slashes in path params#13943
Merged
srittau merged 6 commits intopython:mainfrom May 5, 2025
Merged
pytype_test: support either slashes in path params#13943srittau merged 6 commits intopython:mainfrom
pytype_test: support either slashes in path params#13943srittau merged 6 commits intopython:mainfrom
Conversation
Avasam
commented
May 4, 2025
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}") |
Collaborator
Author
There was a problem hiding this comment.
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
Collaborator
There was a problem hiding this comment.
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
approved these changes
May 5, 2025
mmingyu
pushed a commit
to mmingyu/typeshed
that referenced
this pull request
May 16, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Extracted from #13795
Fixes #13936
Removes all usages of
os.path.sepAlternatively: use
os.path.normpath. But I went thepathlibroute.