Skip to content

Commit

Permalink
update codegen to use literal unions for enums
Browse files Browse the repository at this point in the history
  • Loading branch information
jprochazk committed May 22, 2024
1 parent 25977ee commit 970bcab
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 13 deletions.
7 changes: 6 additions & 1 deletion crates/re_types_builder/src/codegen/python/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,12 @@ fn code_for_enum(
}
}

code.push_unindented(format!("{name}Like = Union[{name}, str]"), 1);
let variants = obj
.fields
.iter()
.map(|v| format!("Literal[{:?}]", v.snake_case_name()))
.join(" | ");
code.push_unindented(format!("{name}Like = Union[{name}, {variants}]"), 1);
code.push_unindented(
format!(
r#"
Expand Down
2 changes: 2 additions & 0 deletions rerun_py/rerun_sdk/rerun/blueprint/__init__.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions rerun_py/rerun_sdk/rerun/blueprint/components/corner2d.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions rerun_py/rerun_sdk/rerun/blueprint/components/panel_state.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 14 additions & 2 deletions rerun_py/rerun_sdk/rerun/components/marker_shape.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions rerun_py/tests/test_types/components/enum_test.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 970bcab

Please sign in to comment.