Reduce duplication in utils converters and type checkers

TL;DR

  • The six sequence/vector converters and the six is_*_type predicates in tango/utils.py now share one implementation each, instead of repeating it per type. No behaviour change.
  • dir2 no longer walks every base class twice.

Reported in #789. Removes about 80 lines.

Key Facts

  • Public functions keep their names, signatures and docstrings. Only the bodies move into two converter helpers and one predicate helper. Nothing is generated dynamically, so the API docs and autofunction entries are unaffected.
  • The TypeError text is still derived from the container type, so the messages are byte-identical — verified: vec must be a tango.StdStringVector, vec must be a tango.StdDoubleVector.
  • This is the change #789 identifies as the reason the is_binary defect went unnoticed: five predicates honoured inc_array and the sixth silently did not, because each carried its own copy of the three branches. After this, the pair of tuples is the only thing a predicate chooses.
  • seq_2_DbDevInfos and seq_2_DbDevExportInfos were identical apart from a class name in three places.
  • dir2 called get_attrs(cls) and then dir2(cls) for each base, and dir2(cls) already contributes get_attrs(cls) for a class argument. The result is a set, so only the duplicated work changes. Verified by diffing the output of the old and new implementations over DeviceProxy, DevFailed, CaselessList, CaselessDict, an int and a str: identical in every case.

Caveats

  • document_method / document_static_method are deliberately left alone, although #789 lists them. They are less parallel than they look: document_method returns early when add is true and the C++ docstring is non-empty, which skips the __name__ fix-up below it. Consolidating the two would silently change when that fix-up runs, across every method the bindings document. That looks like an accidental early return and is worth a maintainer's view, but it is a behaviour question rather than a duplication one, so it does not belong in this MR.
  • No tests are added. This is a refactor with no new behaviour; it is covered by the tests the preceding MRs added over the same functions, plus existing coverage of the converters.
  • Builds on !1077 (merged) and targets its branch. Retarget as the chain merges.

🤖 Generated with Claude Code

Merge request reports

Loading
Loading