Skip to content

Commit

Permalink
make attribute name more pythonic
Browse files Browse the repository at this point in the history
  • Loading branch information
tim committed Feb 19, 2024
1 parent 9831df2 commit fe37805
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions demo/charts.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ def charts_content_view(kind: str) -> list[AnyComponent]:
width='100%',
height=300,
data=data_list,
xKey='name',
yKeys=['pv', 'uv', 'amt'],
yKeysNames=['Page Views', 'Unique Views', 'Amount'],
x_key='name',
y_keys=['pv', 'uv', 'amt'],
y_keys_names=['Page Views', 'Unique Views', 'Amount'],
colors=['#8884d8', '#82ca9d', '#ffc658'],
),
]
Expand Down
22 changes: 11 additions & 11 deletions src/python-fastui/fastui/components/charts.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import typing as _t
from abc import ABC

import pydantic
import pydantic as _p

from .. import class_name as _class_name

if _t.TYPE_CHECKING:
pass

Check warning on line 9 in src/python-fastui/fastui/components/charts.py

View check run for this annotation

Codecov / codecov/patch

src/python-fastui/fastui/components/charts.py#L9

Added line #L9 was not covered by tests


DataPoint = _t.TypeVar('DataPoint', bound=pydantic.BaseModel)
DataPoint = _t.TypeVar('DataPoint', bound=_p.BaseModel)


class BaseChart(pydantic.BaseModel, ABC, defer_build=True):
class BaseChart(_p.BaseModel, ABC, defer_build=True):
title: str
width: _t.Union[int, str] = '100%'
height: _t.Union[int, str]
Expand All @@ -22,16 +22,16 @@ class BaseChart(pydantic.BaseModel, ABC, defer_build=True):

class RechartsLineChart(BaseChart):
type: _t.Literal['RechartsLineChart'] = 'RechartsLineChart'
xKey: str
yKeys: _t.List[str]
yKeysNames: _t.Union[_t.List[str], None] = None
x_key: str = _p.Field(..., serialization_alias='xKey')
y_keys: _t.List[str] = _p.Field(..., serialization_alias='yKeys')
y_keys_names: _t.Union[_t.List[str], None] = _p.Field(None, serialization_alias='yKeysNames')
colors: _t.List[str]
tooltip: bool = True

@pydantic.model_validator(mode='after')
@_p.model_validator(mode='after')
def check_length_of_y_keys_colors_and_y_keys_names(self):
if len(self.yKeys) != len(self.colors):
raise pydantic.ValidationError('Length of yKeys and colors must be the same')
if self.yKeysNames and len(self.yKeys) != len(self.yKeysNames):
raise pydantic.ValidationError('Length of yKeys and yKeysNames must be the same')
if len(self.y_keys) != len(self.colors):
raise _p.ValidationError('Length of y_keys and colors must be the same')
if self.y_keys_names and len(self.y_keys) != len(self.y_keys_names):
raise _p.ValidationError('Length of y_keys and y_keys_names must be the same')
return self

Check warning on line 37 in src/python-fastui/fastui/components/charts.py

View check run for this annotation

Codecov / codecov/patch

src/python-fastui/fastui/components/charts.py#L33-L37

Added lines #L33 - L37 were not covered by tests

0 comments on commit fe37805

Please sign in to comment.