Skip to content

Whitespace in enums creates invalid syntax #68

@chrispahm

Description

@chrispahm

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions