cellml / libcellml

Repository for libCellML development.
https://libcellml.org
Apache License 2.0
17 stars 21 forks source link

Python code generation: Initialise enums from zero #991

Closed hsorby closed 1 year ago

hsorby commented 2 years ago

For code generation of the Python profile enumerations of the VariableType are initialised to start at 1. However, the C++ equivalent is initialised at 0. I think this should be made consistent across the code generation profiles.

This means initialising our Python generated enumeration code to start from 0 and not 1.

agarny commented 2 years ago

The reason for starting from 1 is that it's what is done by default in Python (see https://docs.python.org/3/library/enum.html#enum.auto), e.g.

from enum import Enum, auto

class Color(Enum):
    RED = auto()
    GREEN = auto()
    BLUE = auto()

is the same as:

from enum import Enum

class Color(Enum):
    RED = 1
    GREEN = 2
    BLUE = 3

So, if we want to generate Python code that looks Pythonic (rather than like C) then I would stick to what we have. So, if anything, I would use auto()-based version.

hsorby commented 2 years ago

While I am very much in favour of making the generated code look Pythonic, I also want to get consistency across the code generation. Currently, when I compare the enumerated values for variables from the generated code from different profiles I get back different values. This to me is a problem that overrides the desire to be Pythonic.

agarny commented 2 years ago

Why would an end user want / need to do such a comparison?