55import re
66import tempfile
77import textwrap
8- from typing import (
9- Any ,
10- Callable ,
11- Iterable ,
12- Literal ,
13- Optional ,
14- Sequence ,
15- TypeVar ,
16- Union ,
17- cast ,
18- )
8+ from typing import Any , Literal , Optional , Sequence , TypeVar
199
2010from htmltools import HTMLDependency
2111
3222T = TypeVar ("T" , bound = "Theme" )
3323
3424
35- SassImporterReturnValue = Union ["tuple[str]" , "tuple[str, str]" , "tuple[str, str, str]" ]
36- SassImporterFunction = Union [
37- Callable [[str ], SassImporterReturnValue ],
38- Callable [[str , str ], SassImporterReturnValue ],
39- ]
40-
41-
4225class SassCompileArgs (TypedDict ):
4326 output_style : NotRequired [Literal ["nested" , "expanded" , "compact" , "compressed" ]]
4427 source_comments : NotRequired [bool ]
@@ -50,7 +33,7 @@ class SassCompileArgs(TypedDict):
5033 precision : NotRequired [int ]
5134 custom_functions : NotRequired [Any ] # not worth the effort, it's a complicated type
5235 indented : NotRequired [bool ]
53- importers : NotRequired [Iterable [ tuple [ int , SassImporterFunction ]] | None ]
36+ importers : NotRequired [Any ] # not worth the effort, it's a complicated type
5437
5538
5639theme_temporary_directories : set [tempfile .TemporaryDirectory [str ]] = set ()
@@ -416,17 +399,21 @@ def to_css(
416399 check_libsass_installed ()
417400 import sass
418401
419- if compile_args is None :
420- compile_args = {"output_style" : "compressed" }
402+ args : SassCompileArgs = {} if compile_args is None else compile_args
421403
422- self ._css = cast (
423- str ,
424- sass .compile (
425- string = self .to_sass (),
426- include_paths = self ._include_paths ,
427- ** compile_args , # type: ignore
428- ),
429- )
404+ if "include_paths" in args :
405+ raise ValueError (
406+ "The 'include_paths' argument is not allowed in 'compile_args'. "
407+ "Use the 'include_paths' argument of the Theme constructor instead." ,
408+ )
409+
410+ args : SassCompileArgs = {
411+ "output_style" : "compressed" ,
412+ "include_paths" : self ._include_paths ,
413+ ** args ,
414+ }
415+
416+ self ._css = sass .compile (string = self .to_sass (), ** args )
430417
431418 return self ._css
432419
0 commit comments