Skip to content

Commit 6e56d11

Browse files
committed
Avoid subtracting -1 from the number of possible enum values
1 parent 292db90 commit 6e56d11

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

pyvips/base.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,12 @@ def values_for_enum(gtype):
117117
g_type_class = gobject_lib.g_type_class_ref(gtype)
118118
g_enum_class = ffi.cast('GEnumClass *', g_type_class)
119119

120-
# -1 since we always have a "last" member.
121-
return [_to_string(g_enum_class.values[i].value_nick)
122-
for i in range(g_enum_class.n_values - 1)]
120+
result = [_to_string(g_enum_class.values[i].value_nick)
121+
for i in range(g_enum_class.n_values)]
122+
# FIXME(kleisauke): remove after https://github.com/libvips/libvips/pull/4520
123+
if 'last' in result:
124+
result.remove('last')
125+
return result
123126

124127

125128
def values_for_flag(gtype):
@@ -138,10 +141,12 @@ def enum_dict(gtype):
138141
g_type_class = gobject_lib.g_type_class_ref(gtype)
139142
g_enum_class = ffi.cast('GEnumClass *', g_type_class)
140143

141-
# -1 since we always have a "last" member.
142-
return {_to_string(g_enum_class.values[i].value_nick):
143-
g_enum_class.values[i].value
144-
for i in range(g_enum_class.n_values - 1)}
144+
result = {_to_string(g_enum_class.values[i].value_nick):
145+
g_enum_class.values[i].value
146+
for i in range(g_enum_class.n_values)}
147+
# FIXME(kleisauke): remove after https://github.com/libvips/libvips/pull/4520
148+
result.pop('last', None)
149+
return result
145150

146151

147152
def flags_dict(gtype):

0 commit comments

Comments
 (0)