Skip to content

Avoid subtracting -1 from the number of possible enum values #537

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions examples/gen-enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import xml.etree.ElementTree as ET

from pyvips import ffi, enum_dict, flags_dict, \
vips_lib, type_map, type_name, type_from_name
type_map, type_name, type_from_name

# This file generates enums.py -- the set of classes giving the permissible
# values for the pyvips enums/flags. Run with something like:
Expand Down Expand Up @@ -103,10 +103,6 @@ def add_nickname(gtype, a, b):

type_map(type_from_name('GEnum'), add_nickname)

# Filter internal enums
blacklist = ['VipsImageType', 'VipsToken']
all_nicknames = [name for name in all_nicknames if name not in blacklist]

for name in all_nicknames:
gtype = type_from_name(name)
python_name = remove_prefix(name)
Expand Down Expand Up @@ -198,11 +194,6 @@ def add_nickname(gtype, a, b):


if __name__ == "__main__":
# otherwise we're missing some enums
vips_lib.vips_token_get_type()
vips_lib.vips_saveable_get_type()
vips_lib.vips_image_type_get_type()

print('# libvips enums -- this file is generated automatically')
print('# flake8: noqa: E501') # ignore line too long error
generate_enums()
Expand Down
6 changes: 2 additions & 4 deletions pyvips/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,8 @@ def values_for_enum(gtype):
g_type_class = gobject_lib.g_type_class_ref(gtype)
g_enum_class = ffi.cast('GEnumClass *', g_type_class)

# -1 since we always have a "last" member.
return [_to_string(g_enum_class.values[i].value_nick)
for i in range(g_enum_class.n_values - 1)]
for i in range(g_enum_class.n_values)]


def values_for_flag(gtype):
Expand All @@ -138,10 +137,9 @@ def enum_dict(gtype):
g_type_class = gobject_lib.g_type_class_ref(gtype)
g_enum_class = ffi.cast('GEnumClass *', g_type_class)

# -1 since we always have a "last" member.
return {_to_string(g_enum_class.values[i].value_nick):
g_enum_class.values[i].value
for i in range(g_enum_class.n_values - 1)}
for i in range(g_enum_class.n_values)}


def flags_dict(gtype):
Expand Down
Loading