Skip to content

fix: replace mutable default argument in get_all_uids#391

Closed
t7929375-eng wants to merge 3 commits intoentrius:testfrom
t7929375-eng:fix/mutable-default-get-all-uids
Closed

fix: replace mutable default argument in get_all_uids#391
t7929375-eng wants to merge 3 commits intoentrius:testfrom
t7929375-eng:fix/mutable-default-get-all-uids

Conversation

@t7929375-eng
Copy link
Copy Markdown
Contributor

@t7929375-eng t7929375-eng commented Apr 12, 2026

Summary

get_all_uids() uses a mutable default argument (exclude: List[int] = []). This is a well-known Python anti-pattern (W0102) — the shared default object is permanently corrupted if mutated.

Replaced with Optional[List[int]] = None and an explicit guard.

Type of Change

  • Bug fix

Testing

  • 5 unit tests in tests/utils/test_uids.py (UID enumeration, exclusion, UID 0 forced inclusion, regression test for shared default, empty metagraph)
  • ruff check passes
  • pyright passes
  • All existing tests pass

Checklist

  • Code follows project style guidelines
  • Self-review completed
  • Tests added

cc @anderdc @LandynDev

t7929375-eng and others added 3 commits April 12, 2026 14:03
Covers:
- Basic UID enumeration with and without exclusions
- UID 0 forced inclusion
- Regression: default exclude list not shared across calls
- Edge case: empty metagraph
@anderdc anderdc closed this Apr 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants