Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork3.1k
Make is_sub_path faster#17962
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Make is_sub_path faster#17962
Changes from1 commit
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -410,8 +410,23 @@ def replace_object_state( | ||
| pass | ||
| def is_sub_path_normabs(path: str, dir: str) -> bool: | ||
| """Given two paths, return if path is a sub-path of dir. | ||
| Moral equivalent of: Path(dir) in Path(path).parents | ||
| Similar to the pathlib version: | ||
| - Treats paths case-sensitively | ||
| - Does not fully handle unnormalised paths (e.g. paths with "..") | ||
| - Does not handle a mix of absolute and relative paths | ||
| Unlike the pathlib version: | ||
| - Fast | ||
| - On Windows, assumes input has been slash normalised | ||
| - Handles even fewer unnormalised paths (e.g. paths with "." and "//") | ||
| As a result, callers should ensure that inputs have had os.path.abspath called on them | ||
| (note that os.path.abspath will normalise) | ||
| """ | ||
| if not dir.endswith(os.sep): | ||
| dir += os.sep | ||
| return path.startswith(dir) | ||
Collaborator There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Does this will work reliably on Windows, where path separators can be Maybe update docstring to mention Windows-specific issues, and case insensitivity issues? CollaboratorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Documented the shortcomings of the faster function + invariants we require in modulefinder. Also renamed the function so it sounds a little scarier | ||