Repository navigation
Replies: 3 comments
|
I am not sure what is the neat/correct way of solving it, SO has all sort of answers (https://stackoverflow.com/questions/41407414/convert-string-to-enum-in-python) this stands out as a neat one: https://stackoverflow.com/a/56567247 |
0 replies
hence calling code can be change from: to: this way both |
0 replies
Another issue...with displaying/repr for classes having enums, displayed text has nasty looking ObjectInfo(created_at=1677658169185, language=<Language.SQL: 'SQL'>, modified_at=1677658409090, object_id=3538949529947478, object_type=<ObjectType.NOTEBOOK: 'NOTEBOOK'>, path='/Users/grzegorz.rusin@databricks.com/auto-dlt/generated/gr_products/gr_silver-incremental', size=None)]displayed text should look like this, so it can be copied and run to created object back: from databricks.sdk.service.workspace import ObjectType, Language, ObjectInfo
ObjectInfo(created_at=1677658169185, language=Language.SQL, modified_at=1677658409090, object_id=3538949529947478, object_type=ObjectType.NOTEBOOK, path='/Users/grzegorz.rusin@databricks.com/auto-dlt/generated/gr_products/gr_silver-incremental', size=None)Solution:adding custom string formatter: class YetAnotherStrEnum(Enum):
...
def __repr__(self):
return str(self)gets rid of nasty EnumType.FieldName: FieldValue formatting, in favour of just EnumType.FieldName |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Problem
Generated Enum types does not have support of being instantiated from string, hence it forces end users to not use non pythonic syntax of:
instead of neat, short, and pythonic:
throws an exception:
Example
For example:
has signature of:
in turn parameter
formatis of Enum type defined indatabricks.sdk.service.workspace.ExportFormatasAll reactions