-
-
Notifications
You must be signed in to change notification settings - Fork 19.5k
TYP use typeddict to define cssdict #40947
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
8166430
3c98fcb
af5b3b8
1d5c6c1
ab033a0
b6aa69f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,6 @@ | |
| Sequence, | ||
| Tuple, | ||
| Union, | ||
| cast, | ||
| ) | ||
| from uuid import uuid4 | ||
|
|
||
|
|
@@ -21,7 +20,10 @@ | |
| from pandas._config import get_option | ||
|
|
||
| from pandas._libs import lib | ||
| from pandas._typing import FrameOrSeriesUnion | ||
| from pandas._typing import ( | ||
| FrameOrSeriesUnion, | ||
| TypedDict, | ||
| ) | ||
| from pandas.compat._optional import import_optional_dependency | ||
|
|
||
| from pandas.core.dtypes.generic import ABCSeries | ||
|
|
@@ -45,10 +47,14 @@ | |
| CSSPair = Tuple[str, Union[str, int, float]] | ||
| CSSList = List[CSSPair] | ||
| CSSProperties = Union[str, CSSList] | ||
| CSSStyles = List[Dict[str, CSSProperties]] # = List[CSSDict] | ||
| # class CSSDict(TypedDict): # available when TypedDict is valid in pandas | ||
| # selector: str | ||
| # props: CSSProperties | ||
|
|
||
|
|
||
| class CSSDict(TypedDict): | ||
| selector: str | ||
| props: CSSProperties | ||
|
|
||
|
|
||
| CSSStyles = List[CSSDict] | ||
|
|
||
|
|
||
| class StylerRenderer: | ||
|
|
@@ -617,9 +623,9 @@ def _format_table_styles(styles: CSSStyles) -> CSSStyles: | |
| return [ | ||
| item | ||
| for sublist in [ | ||
| [ # this is a CSSDict when TypedDict is available to avoid cast. | ||
| {"selector": x, "props": style["props"]} | ||
| for x in cast(str, style["selector"]).split(",") | ||
| [ | ||
| CSSDict(selector=x, props=style["props"]) | ||
| for x in style["selector"].split(",") | ||
|
||
| ] | ||
| for style in styles | ||
| ] | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we don't need to use the TypedDict at runtime, then we would not need this and we could only use TypedDict in TYPE_CHECKING blocks.
I see the downside being that aliases (and imports of aliases) would also need to be defined in the TYPE_CHECKING block and that we would not be able to construct the TypedDict explicitly in code. but that could be an upside.
no strong preference here yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thinking some more. leave this for now.
from NEP 29, Dec 26, 2021 drop support for Python 3.7
so we should be able to drop python 3.7 on master after the 1.3 release.