1- """Utilities for interpreting CSS from Stylers for formatting non-HTML outputs
1+ """
2+ Utilities for interpreting CSS from Stylers for formatting non-HTML outputs.
23"""
34
45import re
56import warnings
67
78
89class CSSWarning (UserWarning ):
9- """This CSS syntax cannot currently be parsed"""
10+ """
11+ This CSS syntax cannot currently be parsed.
12+ """
1013
1114 pass
1215
1316
1417def _side_expander (prop_fmt : str ):
15- def expand (self , prop , value ):
18+ """
19+ Parameters
20+ ----------
21+ prop_fmt : str
22+ """
23+
24+ def expand (self , prop , value : str ):
25+ """
26+ Parameters
27+ ----------
28+ prop
29+ value : str
30+ """
1631 tokens = value .split ()
1732 try :
1833 mapping = self .SIDE_SHORTHANDS [len (tokens )]
1934 except KeyError :
2035 warnings .warn (
21- f' Could not expand " { prop } : { value } "' , CSSWarning ,
36+ f" Could not expand { prop } : { value } " , CSSWarning ,
2237 )
2338 return
2439 for key , idx in zip (self .SIDES , mapping ):
@@ -28,12 +43,13 @@ def expand(self, prop, value):
2843
2944
3045class CSSResolver :
31- """A callable for parsing and resolving CSS to atomic properties
32-
46+ """
47+ A callable for parsing and resolving CSS to atomic properties.
3348 """
3449
3550 def __call__ (self , declarations_str , inherited = None ):
36- """ the given declarations to atomic properties
51+ """
52+ The given declarations to atomic properties.
3753
3854 Parameters
3955 ----------
@@ -46,8 +62,8 @@ def __call__(self, declarations_str, inherited=None):
4662
4763 Returns
4864 -------
49- props : dict
50- Atomic CSS 2.2 properties
65+ dict
66+ Atomic CSS 2.2 properties.
5167
5268 Examples
5369 --------
@@ -69,7 +85,6 @@ def __call__(self, declarations_str, inherited=None):
6985 ('font-size', '24pt'),
7086 ('font-weight', 'bold')]
7187 """
72-
7388 props = dict (self .atomize (self .parse (declarations_str )))
7489 if inherited is None :
7590 inherited = {}
@@ -172,7 +187,9 @@ def __call__(self, declarations_str, inherited=None):
172187
173188 def size_to_pt (self , in_val , em_pt = None , conversions = UNIT_RATIOS ):
174189 def _error ():
175- warnings .warn (f"Unhandled size: { repr (in_val )} " , CSSWarning )
190+ warnings .warn (
191+ f"Unhandled size: { repr (in_val )} " , CSSWarning ,
192+ )
176193 return self .size_to_pt ("1!!default" , conversions = conversions )
177194
178195 try :
@@ -235,10 +252,15 @@ def atomize(self, declarations):
235252 expand_margin = _side_expander ("margin-{:s}" )
236253 expand_padding = _side_expander ("padding-{:s}" )
237254
238- def parse (self , declarations_str ):
239- """Generates (prop, value) pairs from declarations
255+ def parse (self , declarations_str : str ):
256+ """
257+ Generates (prop, value) pairs from declarations.
240258
241259 In a future version may generate parsed tokens from tinycss/tinycss2
260+
261+ Parameters
262+ ----------
263+ declarations_str : str
242264 """
243265 for decl in declarations_str .split (";" ):
244266 if not decl .strip ():
0 commit comments