Skip to content

Conversation

@FlorianDeconinck
Copy link
Contributor

@FlorianDeconinck FlorianDeconinck commented Oct 20, 2025

Description

We introduced the (strict) support for IntEnum in code and arguments of stencils. The strategy is to replace them with proper integer as soon as possible.

Guardrails exists for name clash and IntEnum derivation.

Valid code looks like this

@gtscript.enum
class LocalEnum(IntEnum):
    A = 42
    B = 1000

@gtscript.stencil
def enum(field: gtscript.Field[float], order: LocalEnum):  # type: ignore
    with computation(PARALLEL), interval(0, 1):
        if order > LocalEnum.A:
            field[0, 0, 0] = LocalEnum.B

TO CLEAN

  • Register of Enum types should not leave in gtscript
  • ADR
  • Mixed precision

Requirements

  • All fixes and/or new features come with corresponding tests.
  • Important design decisions have been documented in the appropriate ADR inside the docs/development/ADRs/ folder.


def enum(class_: type[IntEnum]):
class_name = class_.__name__
if class_name in _ENUM_REGISTER:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this works and makes for some centralization!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like that ENUM_REGISTER is on gtscript, I will probably move it into it's own little space

Copy link
Contributor

@romanc romanc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks good as proof of concept. Some suggested wording changes inline.

@FlorianDeconinck
Copy link
Contributor Author

Test fails on 3.10, fine on 3.11. Looks like the AST parsing of Enum has moved

@romanc romanc changed the title cartesian[feat]: IntEnum support feat[cartesian]: IntEnum support Oct 21, 2025
@FlorianDeconinck
Copy link
Contributor Author

FlorianDeconinck commented Oct 21, 2025

Test will be happy when #2326 is in

Comment on lines +45 to +46
def get_integer_default_type():
"""Return the integer numpy type corresponding to the LITERAL_INT_PRECISION set."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That won't work with the per-stencil overrides of literal_integer_precision that we allow. In the GTScriptParser, you have access to the BuildOptions in self.options which contains literal_integer_precision. Likewise, in annotate_definition() of the StencilObject you get the BuildOptions as function argument, so you can get the precision from there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants