-
Notifications
You must be signed in to change notification settings - Fork 54
feat[cartesian]: IntEnum support #2323
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
287e55e
5d40789
6267f0f
9c24bc2
44009be
71c27c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ | |
| import inspect | ||
| import numbers | ||
| import types | ||
| from enum import IntEnum | ||
| from typing import Callable, Dict, Type, Union | ||
|
|
||
| import numpy as np | ||
|
|
@@ -159,6 +160,26 @@ def _parse_annotation(arg, annotation): | |
| return original_annotations | ||
|
|
||
|
|
||
| _ENUM_REGISTER: dict[str, object] = {} | ||
| """Register of IntEnum that will be available to parsing in stencils. Register | ||
| with @gtscript.enum()""" | ||
|
|
||
|
|
||
| def enum(class_: type[IntEnum]): | ||
| class_name = class_.__name__ | ||
| if class_name in _ENUM_REGISTER: | ||
|
||
| raise ValueError( | ||
| f"Cannot register @gtscript.enum {class_name} as a class" | ||
| "with the same name is already registered." | ||
FlorianDeconinck marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) | ||
|
|
||
| if not issubclass(class_, IntEnum): | ||
| raise ValueError(f"Enum {class_name} needs to derive from `enum.IntEnum`.") | ||
|
|
||
| _ENUM_REGISTER[class_name] = class_ | ||
| return class_ | ||
|
|
||
|
|
||
| def function(func): | ||
| """Mark a GTScript function.""" | ||
| from gt4py.cartesian.frontend import gtscript_frontend as gt_frontend | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.