Skip to content

Commit

Permalink
Disallow field reordering in Profile
Browse files Browse the repository at this point in the history
  • Loading branch information
etan-status committed Jun 4, 2024
1 parent 22db96b commit b374d35
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions remerkleable/stable_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ def __init_subclass__(cls, **kwargs):
raise TypeError(f'Cannot override `B` inside `{cls.__name__}`')
cls._field_indices = {}
cls._o = 0
last_findex = -1
for (fkey, t) in cls.__annotations__.items():
if fkey not in cls.B._field_indices:
raise TypeError(
Expand All @@ -360,6 +361,12 @@ def __init_subclass__(cls, **kwargs):
else:
findex = cls.B._field_indices[fkey]
ftyp = cls.B.fields()[fkey]
if findex <= last_findex:
raise TypeError(
f'`{cls.__name__}` fields must have the same order as in the base type '
f'but `{fkey}` is defined earlier than in `{cls.B.__name__}`'
)
last_findex = findex
fopt = (
get_origin(t) == PyUnion
and len(get_args(t)) == 2
Expand Down

0 comments on commit b374d35

Please sign in to comment.