Loading
Reduce duplication in utils converters and type checkers
TL;DR
- The six sequence/vector converters and the six
is_*_typepredicates intango/utils.pynow share one implementation each, instead of repeating it per type. No behaviour change. dir2no 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
autofunctionentries are unaffected. - The
TypeErrortext 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_binarydefect went unnoticed: five predicates honouredinc_arrayand 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_DbDevInfosandseq_2_DbDevExportInfoswere identical apart from a class name in three places.dir2calledget_attrs(cls)and thendir2(cls)for each base, anddir2(cls)already contributesget_attrs(cls)for a class argument. The result is aset, so only the duplicated work changes. Verified by diffing the output of the old and new implementations overDeviceProxy,DevFailed,CaselessList,CaselessDict, anintand astr: identical in every case.
Caveats
document_method/document_static_methodare deliberately left alone, although #789 lists them. They are less parallel than they look:document_methodreturns early whenaddis 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.