Skip to content

fix(typing): Resolve LSP violation for ChartType.data#3740

Merged
dangotbanned merged 2 commits intomainfrom
chart-data-type
Jan 2, 2025
Merged

fix(typing): Resolve LSP violation for ChartType.data#3740
dangotbanned merged 2 commits intomainfrom
chart-data-type

Conversation

@dangotbanned
Copy link
Copy Markdown
Member

@dangotbanned dangotbanned commented Jan 2, 2025

Liskov substitution principle (LSP)

Examples

In addition to the changes this allowed in api.py; this PR also removes warnings we currently get for a few examples using alt.LookupData:

main

Argument of type "str" cannot be assigned to parameter "data" of type "Optional[SchemaBase | Map]"
  Type "str" is not assignable to type "Optional[SchemaBase | Map]"
    "str" is not assignable to "SchemaBase"
    "str" is not assignable to "Mapping[str, Any]"
    "str" is not assignable to "UndefinedType"

image

chart-data-type

image

Note

An alternative solution would be using the Any trick.
In this case though, I think adding another alias (e.g. _ChartDataType) might become more confusing as we already have:

ChartDataType: TypeAlias = Optional[Union[DataType, core.Data, str, core.Generator]]

DataType: TypeAlias = Union[
dict[Any, Any], IntoDataFrame, SupportsGeoInterface, DataFrameLike
]

ChartType: TypeAlias = Union[
Chart, RepeatChart, ConcatChart, HConcatChart, VConcatChart, FacetChart, LayerChart
]
ConcatType: TypeAlias = Union[
ChartType,
core.FacetSpec,

@dangotbanned dangotbanned marked this pull request as ready for review January 2, 2025 20:57
@dangotbanned dangotbanned merged commit b6253ff into main Jan 2, 2025
@dangotbanned dangotbanned deleted the chart-data-type branch January 2, 2025 20:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant