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

Use literal unions in python enum codegen #6408

Merged
merged 10 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.pascal_case_name().to_lowercase()))
.join(" | ");
code.push_unindented(format!("{name}Like = Union[{name}, {variants}]"), 1);
code.push_unindented(
format!(
r#"
Expand Down
2 changes: 1 addition & 1 deletion examples/python/blueprint_stocks/blueprint_stocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def style_peak(symbol: str) -> rr.SeriesPoint:
return rr.SeriesPoint(
color=0xFF0000FF,
name=f"{symbol} (peak)",
marker="Up",
marker="up",
)


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.

Loading