diff --git a/marimo/_ast/codegen.py b/marimo/_ast/codegen.py index 79cd43fe590..d62994c7958 100644 --- a/marimo/_ast/codegen.py +++ b/marimo/_ast/codegen.py @@ -124,7 +124,9 @@ def generate_unparsable_cell( def generate_app_constructor(config: Optional[_AppConfig]) -> str: def _format_arg(arg: Any) -> str: if isinstance(arg, str): - return f'"{arg}"' + # Serialize string arguments as r-strings to handle backslashes + # in file paths + return f'r"{arg}"' else: return str(arg) diff --git a/tests/_ast/codegen_data/test_generate_filecontents_empty_with_config.py b/tests/_ast/codegen_data/test_generate_filecontents_empty_with_config.py index 627f51c6085..dce29d0d23a 100644 --- a/tests/_ast/codegen_data/test_generate_filecontents_empty_with_config.py +++ b/tests/_ast/codegen_data/test_generate_filecontents_empty_with_config.py @@ -1,7 +1,7 @@ import marimo __generated_with = "0.4.6" -app = marimo.App(width="full", app_title="test_title") +app = marimo.App(width=r"full", app_title=r"test_title", css_file=r"a\b.css") diff --git a/tests/_ast/test_codegen.py b/tests/_ast/test_codegen.py index c970a03789b..10c85ead18f 100644 --- a/tests/_ast/test_codegen.py +++ b/tests/_ast/test_codegen.py @@ -71,7 +71,9 @@ def test_generate_filecontents_empty() -> None: @staticmethod def test_generate_filecontents_empty_with_config() -> None: - config = _AppConfig(app_title="test_title", width="full") + config = _AppConfig( + app_title="test_title", width="full", css_file=r"a\b.css" + ) contents = wrap_generate_filecontents([], [], config=config) assert contents == get_expected_filecontents( "test_generate_filecontents_empty_with_config"