5
5
import re
6
6
import tempfile
7
7
import 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
19
9
20
10
from htmltools import HTMLDependency
21
11
32
22
T = TypeVar ("T" , bound = "Theme" )
33
23
34
24
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
-
42
25
class SassCompileArgs (TypedDict ):
43
26
output_style : NotRequired [Literal ["nested" , "expanded" , "compact" , "compressed" ]]
44
27
source_comments : NotRequired [bool ]
@@ -50,7 +33,7 @@ class SassCompileArgs(TypedDict):
50
33
precision : NotRequired [int ]
51
34
custom_functions : NotRequired [Any ] # not worth the effort, it's a complicated type
52
35
indented : NotRequired [bool ]
53
- importers : NotRequired [Iterable [ tuple [ int , SassImporterFunction ]] | None ]
36
+ importers : NotRequired [Any ] # not worth the effort, it's a complicated type
54
37
55
38
56
39
theme_temporary_directories : set [tempfile .TemporaryDirectory [str ]] = set ()
@@ -416,17 +399,21 @@ def to_css(
416
399
check_libsass_installed ()
417
400
import sass
418
401
419
- if compile_args is None :
420
- compile_args = {"output_style" : "compressed" }
402
+ args : SassCompileArgs = {} if compile_args is None else compile_args
421
403
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 )
430
417
431
418
return self ._css
432
419
0 commit comments