-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
pytype_test
: support either slashes in path params
#13943
Conversation
tests/pytype_test.py
Outdated
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}") |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
Extracted from #13795
Fixes #13936
Removes all usages of
os.path.sep
Alternatively: use
os.path.normpath
. But I went thepathlib
route.