Skip to content
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

Whitespace in enums creates invalid syntax #68

Open
chrispahm opened this issue Jan 27, 2025 · 0 comments · May be fixed by #69
Open

Whitespace in enums creates invalid syntax #68

chrispahm opened this issue Jan 27, 2025 · 0 comments · May be fixed by #69

Comments

@chrispahm
Copy link

Describe the bug
When converting SQL DDL that contains enums with whitespaces, omm creates invalid Python syntax.
E.g. the following SQL

CREATE TYPE "enum_with_spaces" AS ENUM (
    'some value',
    'another value'
);

Creates this Python output which contains illegal whitespace in the class attributes.

class EnumWithSpaces(str, Enum):
    another value = 'another value'
    some value = 'some value'

Expected behavior
The package should create valid Python code, since enums including whitespace are allowed in SQL and supported by Pythons enum package.

Proposed solution
As outlined in this blog post, the Enum function allows us to specify member names using tuple lists or dicts. This way we can use names with spaces, and the above example can be re-written as:

EnumWithSpaces = Enum(
    value='EnumWithSpaces',
    names=[
        ('another value', 'another value'),
        ('some value', 'some value')
    ]
)

I'll create a PR including the proposed solution!

@chrispahm chrispahm linked a pull request Jan 27, 2025 that will close this issue
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 a pull request may close this issue.

1 participant