Skip to content

refactor: bind attributes and methods in insertion order#350

Merged
shihab-dls merged 2 commits intomainfrom
334_alphabetical_bob
May 1, 2026
Merged

refactor: bind attributes and methods in insertion order#350
shihab-dls merged 2 commits intomainfrom
334_alphabetical_bob

Conversation

@shihab-dls
Copy link
Copy Markdown
Contributor

@shihab-dls shihab-dls commented Apr 30, 2026

closes #344

This PR replaces the use of dir() to search for attributes and methods with walking the class MRO; this provides us with insertion order, and inherited attributes (which __dict__ would not provide).

Summary by CodeRabbit

  • Refactor

    • Improved how attributes are ordered during controller initialization by implementing explicit method resolution order walking, resulting in more predictable and deterministic attribute binding behavior.
  • Tests

    • Updated test expectations for GUI components and attribute listings to align with the new attribute binding order.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 30, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.24%. Comparing base (81f8fad) to head (8f83340).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #350      +/-   ##
==========================================
+ Coverage   91.21%   91.24%   +0.03%     
==========================================
  Files          70       70              
  Lines        2594     2604      +10     
==========================================
+ Hits         2366     2376      +10     
  Misses        228      228              

☔ 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.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 30, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7c7dd506-a8d8-47a0-bd1c-76e775f0c0f0

📥 Commits

Reviewing files that changed from the base of the PR and between 81f8fad and 8f83340.

📒 Files selected for processing (3)
  • src/fastcs/controllers/base_controller.py
  • tests/transports/epics/ca/test_gui.py
  • tests/transports/tango/test_dsr.py

📝 Walkthrough

Walkthrough

Adds a deterministic MRO-walking helper method to BaseController that iterates through base-to-subclass order to collect attribute/method names from each class's __dict__, replacing reliance on dir() for consistent attribute binding order. Test expectations updated to reflect the new ordering.

Changes

Cohort / File(s) Summary
MRO-based attribute binding
src/fastcs/controllers/base_controller.py
Introduces _walk_mro() classmethod that deterministically walks the MRO to build ordered attribute/method list by iterating each class's __dict__, excluding private names and skipping duplicates overridden by subclasses. Updates _bind_attrs() to use this helper instead of dir(type(self)).
Test expectations for reordered attributes
tests/transports/epics/ca/test_gui.py, tests/transports/tango/test_dsr.py
Updated test assertions to reflect new attribute/component ordering produced by the MRO-based binding logic. GUI component list and attribute list expectations reordered accordingly.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

Poem

🐰 From top to tail, in order true,
Our MRO walker hops right through,
No more chaos, no more sort,
Just the order that we sought!
Commands now dance in harmony,
As user-defined as can be. 🌿

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: replacing alphabetical ordering with insertion-order binding for attributes and methods in the controller.
Linked Issues check ✅ Passed The pull request successfully addresses issue #344 by implementing MRO-walking to preserve insertion order instead of alphabetical order, removing the sort and allowing user-defined declaration order.
Out of Scope Changes check ✅ Passed All changes are scoped to the insertion-order binding objective: the MRO helper method in base_controller.py and corresponding test updates to reflect new ordering.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 334_alphabetical_bob

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 60 minutes.

Comment @coderabbitai help to get the list of available commands and usage tips.

@shihab-dls shihab-dls merged commit fb03263 into main May 1, 2026
11 checks passed
@shihab-dls shihab-dls deleted the 334_alphabetical_bob branch May 1, 2026 11:15
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.

bob file generates commands in alphabetical order

2 participants