File tree Expand file tree Collapse file tree 2 files changed +21
-16
lines changed
Expand file tree Collapse file tree 2 files changed +21
-16
lines changed Original file line number Diff line number Diff line change 3636# and use a string literal forward reference to it in subsequent types
3737# https://mypy.readthedocs.io/en/latest/common_issues.html#import-cycles
3838if TYPE_CHECKING :
39- from typing import final
39+ from typing import (
40+ TypedDict ,
41+ final ,
42+ )
4043
4144 from pandas ._libs import (
4245 Period ,
7073else :
7174 # typing.final does not exist until py38
7275 final = lambda x : x
76+ # typing.TypedDict does not exist until py38
77+ TypedDict = dict
7378
7479
7580# array-like
Original file line number Diff line number Diff line change 1212 Sequence ,
1313 Tuple ,
1414 Union ,
15- cast ,
1615)
1716from uuid import uuid4
1817
2120from pandas ._config import get_option
2221
2322from pandas ._libs import lib
24- from pandas ._typing import FrameOrSeriesUnion
23+ from pandas ._typing import (
24+ FrameOrSeriesUnion ,
25+ TypedDict ,
26+ )
2527from pandas .compat ._optional import import_optional_dependency
2628
2729from pandas .core .dtypes .generic import ABCSeries
4547CSSPair = Tuple [str , Union [str , int , float ]]
4648CSSList = List [CSSPair ]
4749CSSProperties = 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 ]
5258
5359
5460class StylerRenderer :
@@ -583,15 +589,9 @@ def _format_table_styles(styles: CSSStyles) -> CSSStyles:
583589 {'selector': 'th', 'props': 'a:v;'}]
584590 """
585591 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 ("," )
595595 ]
596596
597597
You can’t perform that action at this time.
0 commit comments