File tree 2 files changed +21
-16
lines changed
2 files changed +21
-16
lines changed Original file line number Diff line number Diff line change 36
36
# and use a string literal forward reference to it in subsequent types
37
37
# https://mypy.readthedocs.io/en/latest/common_issues.html#import-cycles
38
38
if TYPE_CHECKING :
39
- from typing import final
39
+ from typing import (
40
+ TypedDict ,
41
+ final ,
42
+ )
40
43
41
44
from pandas ._libs import (
42
45
Period ,
70
73
else :
71
74
# typing.final does not exist until py38
72
75
final = lambda x : x
76
+ # typing.TypedDict does not exist until py38
77
+ TypedDict = dict
73
78
74
79
75
80
# array-like
Original file line number Diff line number Diff line change 12
12
Sequence ,
13
13
Tuple ,
14
14
Union ,
15
- cast ,
16
15
)
17
16
from uuid import uuid4
18
17
21
20
from pandas ._config import get_option
22
21
23
22
from pandas ._libs import lib
24
- from pandas ._typing import FrameOrSeriesUnion
23
+ from pandas ._typing import (
24
+ FrameOrSeriesUnion ,
25
+ TypedDict ,
26
+ )
25
27
from pandas .compat ._optional import import_optional_dependency
26
28
27
29
from pandas .core .dtypes .generic import ABCSeries
45
47
CSSPair = Tuple [str , Union [str , int , float ]]
46
48
CSSList = List [CSSPair ]
47
49
CSSProperties = Union [str , CSSList ]
48
- CSSStyles = List [Dict [str , CSSProperties ]] # = List[CSSDict]
49
- # class CSSDict(TypedDict): # available when TypedDict is valid in pandas
50
- # selector: str
51
- # props: CSSProperties
50
+
51
+
52
+ class CSSDict (TypedDict ):
53
+ selector : str
54
+ props : CSSProperties
55
+
56
+
57
+ CSSStyles = List [CSSDict ]
52
58
53
59
54
60
class StylerRenderer :
@@ -583,15 +589,9 @@ def _format_table_styles(styles: CSSStyles) -> CSSStyles:
583
589
{'selector': 'th', 'props': 'a:v;'}]
584
590
"""
585
591
return [
586
- item
587
- for sublist in [
588
- [ # this is a CSSDict when TypedDict is available to avoid cast.
589
- {"selector" : x , "props" : style ["props" ]}
590
- for x in cast (str , style ["selector" ]).split ("," )
591
- ]
592
- for style in styles
593
- ]
594
- for item in sublist
592
+ {"selector" : selector , "props" : css_dict ["props" ]}
593
+ for css_dict in styles
594
+ for selector in css_dict ["selector" ].split ("," )
595
595
]
596
596
597
597
You can’t perform that action at this time.
0 commit comments