Skip to content

Fix type annotation in upload sync path prefix calculation#1794

Merged
yarikoptic merged 1 commit intomasterfrom
enh-lad-type-annotations
Feb 13, 2026
Merged

Fix type annotation in upload sync path prefix calculation#1794
yarikoptic merged 1 commit intomasterfrom
enh-lad-type-annotations

Conversation

@yarikoptic-gitmate
Copy link
Collaborator

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:

  • reduce expects a binary function that takes two arguments
  • os.path.commonprefix already accepts a list/sequence of paths

Solution

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

  • Removed incorrect reduce() usage
  • Removed from functools import reduce (no longer needed)
  • Removed # type: ignore[arg-type] comment

Benefits

  • Clearer, more correct code
  • Removes one unnecessary type: ignore comment
  • Uses standard library function as intended

Files Changed

  • dandi/upload.py

Testing

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]

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]>
@yarikoptic-gitmate yarikoptic-gitmate added enhancement New feature or request code quality Nonfunctional improvements to the codebase labels Feb 12, 2026
@codecov
Copy link

codecov bot commented Feb 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.10%. Comparing base (a3dd9f9) to head (a2a5bc0).
⚠️ Report is 10 commits behind head on master.

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              
Flag Coverage Δ
unittests 75.10% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@yarikoptic yarikoptic added the patch Increment the patch version when merged label 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)
Copy link
Member

Choose a reason for hiding this comment

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

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

@yarikoptic yarikoptic merged commit 82f9610 into master Feb 13, 2026
38 of 44 checks passed
@yarikoptic yarikoptic deleted the enh-lad-type-annotations branch February 13, 2026 21:16
@github-actions
Copy link

🚀 PR was released in 0.74.3 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code quality Nonfunctional improvements to the codebase enhancement New feature or request patch Increment the patch version when merged released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants