address review: iterate bases right-to-left so leftmost wins (MRO)

Python attribute lookup picks the first base that defines the attr; the
previous left-to-right update() order caused later bases to override
earlier ones, contradicting MRO. Reversing the iteration makes the
leftmost base the final writer, which matches Python semantics for the
common single-chain hierarchies in db_engine_specs.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Evan Rusackas
2026-04-22 19:22:11 -07:00
parent 12d6b2f5b7
commit ff37592986

View File

@@ -348,8 +348,11 @@ def get_resolved_caps(class_name, visited=None):
resolved_attrs = dict(CAP_ATTR_DEFAULTS)
resolved_methods = set()
# Collect from parents first
for base_name in info['bases']:
# Collect from parents, iterating right-to-left so leftmost bases win
# (matches Python MRO: for class C(A, B), A's attributes take precedence).
# update() keeps the LAST value written, so reversing makes the leftmost
# base the final writer.
for base_name in reversed(info['bases']):
parent_attrs, parent_methods = get_resolved_caps(base_name, visited.copy())
resolved_attrs.update(parent_attrs)
resolved_methods.update(parent_methods)