Fix type annotation in upload sync path prefix calculation#1794
Merged
yarikoptic merged 1 commit intomasterfrom Feb 13, 2026
Merged
Fix type annotation in upload sync path prefix calculation#1794yarikoptic merged 1 commit intomasterfrom
yarikoptic merged 1 commit intomasterfrom
Conversation
Replace incorrect use of reduce() with direct os.path.commonprefix() call. The original code used reduce() incorrectly - os.path.commonprefix() already accepts a list of paths and returns the longest common prefix. This removes one type: ignore comment and improves code clarity. Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1794 +/- ##
==========================================
- Coverage 75.11% 75.10% -0.01%
==========================================
Files 84 84
Lines 11921 11920 -1
==========================================
- Hits 8954 8953 -1
Misses 2967 2967
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
yarikoptic
approved these changes
Feb 13, 2026
| rp = os.path.relpath(p, dandiset.path) | ||
| relpaths.append("" if rp == "." else rp) | ||
| path_prefix = reduce(os.path.commonprefix, relpaths) # type: ignore[arg-type] | ||
| path_prefix = os.path.commonprefix(relpaths) |
Member
There was a problem hiding this comment.
not sure how it should have worked even
In [5]: reduce(os.path.commonprefix, ['1/1','1/1/12','1/3'])
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[5], line 1
----> 1 reduce(os.path.commonprefix, ['1/1','1/1/12','1/3'])
TypeError: commonprefix() takes 1 positional argument but 2 were given
In [6]: reduce(os.path.commonprefix, ['1/1','1/1/12'])
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[6], line 1
----> 1 reduce(os.path.commonprefix, ['1/1','1/1/12'])
TypeError: commonprefix() takes 1 positional argument but 2 were given
In [7]: reduce(os.path.commonprefix, ['1/1'])
Out[7]: '1/1'
but that means that we do not unittest this case at all. this spaghetti code though is too long/deep to craft a test now I think... will just proceed
|
🚀 PR was released in |
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.
Fixes incorrect use of reduce() in upload.py by using os.path.commonprefix() directly, improving code clarity and removing unnecessary type: ignore comment.
Problem
The code used
reduce(os.path.commonprefix, relpaths)which is incorrect because:reduceexpects a binary function that takes two argumentsos.path.commonprefixalready accepts a list/sequence of pathsSolution
Replace with direct call:
os.path.commonprefix(relpaths)This is the correct usage since os.path.commonprefix is designed to take a list of paths and return the longest common prefix.
Changes
reduce()usagefrom functools import reduce(no longer needed)# type: ignore[arg-type]commentBenefits
Files Changed
dandi/upload.pyTesting
Verified with full test suite: 548 passed, 0 failed.
Sync functionality tested in integration tests (require Docker).
Note: This PR may have minor conflicts with # and # if those haven't merged yet. All three modify upload.py but in different sections.
See commit: 649d7565
Co-Authored-By: Claude Sonnet 4.5 [email protected]