Skip to content

Commit

Permalink
Add: mypy checker (pyecharts#1106)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiandongx authored May 13, 2019
1 parent 002c578 commit d7bb09a
Show file tree
Hide file tree
Showing 31 changed files with 39 additions and 45 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,6 @@ ENV/
# example
example/*.png
example/*.html

# mypy
.mypy_cache/
2 changes: 1 addition & 1 deletion pyecharts/charts/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Base:
`Base`类是所有图形类的基类,提供部分初始化参数和基本的方法
"""

def __init__(self, init_opts: Union[InitOpts, dict] = InitOpts()):
def __init__(self, init_opts: InitOpts = InitOpts()):
self.width = init_opts.width
self.height = init_opts.height
self.renderer = init_opts.renderer
Expand Down
2 changes: 1 addition & 1 deletion pyecharts/charts/basic_charts/bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Bar(RectChart):
with heights or lengths proportional to the values that they represent.
"""

def __init__(self, init_opts: Union[opts.InitOpts, dict] = opts.InitOpts()):
def __init__(self, init_opts: opts.InitOpts = opts.InitOpts()):
super().__init__(init_opts=init_opts)
self.options.update(yAxis=[opts.AxisOpts().opts])

Expand Down
2 changes: 1 addition & 1 deletion pyecharts/charts/basic_charts/bmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class BMap(GeoChartBase):
Support scatter plot, line
"""

def __init__(self, init_opts: Union[opts.InitOpts, dict] = opts.InitOpts()):
def __init__(self, init_opts: opts.InitOpts = opts.InitOpts()):
super().__init__(init_opts=init_opts)
self.js_dependencies.add("bmap")
self._is_geo_chart = True
Expand Down
2 changes: 1 addition & 1 deletion pyecharts/charts/basic_charts/boxplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Boxplot(RectChart):
of a set of data.
"""

def __init__(self, init_opts: Union[opts.InitOpts, dict] = opts.InitOpts()):
def __init__(self, init_opts: opts.InitOpts = opts.InitOpts()):
super().__init__(init_opts=init_opts)
self.options.update(yAxis=[opts.AxisOpts().opts])

Expand Down
2 changes: 1 addition & 1 deletion pyecharts/charts/basic_charts/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Calendar(Chart):
Two categories of axes must be used in rectangular coordinates.
"""

def __init__(self, init_opts: Union[opts.InitOpts, dict] = opts.InitOpts()):
def __init__(self, init_opts: opts.InitOpts = opts.InitOpts()):
super().__init__(init_opts=init_opts)
self.options.update(calendar=opts.CalendarOpts().opts)

Expand Down
2 changes: 1 addition & 1 deletion pyecharts/charts/basic_charts/effectscatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class EffectScatter(RectChart):
Use animation effects to visually highlight designated data set.
"""

def __init__(self, init_opts: Union[opts.InitOpts, dict] = opts.InitOpts()):
def __init__(self, init_opts: opts.InitOpts = opts.InitOpts()):
super().__init__(init_opts=init_opts)
self.options.update(yAxis=[opts.AxisOpts().opts])

Expand Down
2 changes: 1 addition & 1 deletion pyecharts/charts/basic_charts/funnel.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Funnel(Chart):
and then decisions can be made.
"""

def __init__(self, init_opts: Union[opts.InitOpts, dict] = opts.InitOpts()):
def __init__(self, init_opts: opts.InitOpts = opts.InitOpts()):
super().__init__(init_opts=init_opts)

def add(
Expand Down
2 changes: 1 addition & 1 deletion pyecharts/charts/basic_charts/gauge.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Gauge(Chart):
The gauge displays a single key business measure.
"""

def __init__(self, init_opts: Union[opts.InitOpts, dict] = opts.InitOpts()):
def __init__(self, init_opts: opts.InitOpts = opts.InitOpts()):
super().__init__(init_opts=init_opts)

def add(
Expand Down
6 changes: 3 additions & 3 deletions pyecharts/charts/basic_charts/geo.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


class GeoChartBase(Chart):
def __init__(self, init_opts: Union[opts.InitOpts, dict] = opts.InitOpts()):
def __init__(self, init_opts: opts.InitOpts = opts.InitOpts()):
super().__init__(init_opts=init_opts)
self.set_global_opts()
self._coordinates = COORDINATES
Expand All @@ -27,7 +27,7 @@ def add_coordinate_json(self, json_file: str):
self.add_coordinate(k, v[0], v[1])
return self

def get_coordinate(self, name: str) -> Sequence:
def get_coordinate(self, name: str) -> Optional[Sequence]:
if name in self._coordinates:
return self._coordinates[name]

Expand Down Expand Up @@ -165,7 +165,7 @@ class Geo(GeoChartBase):
support scatter plot and line
"""

def __init__(self, init_opts: Union[opts.InitOpts, dict] = opts.InitOpts()):
def __init__(self, init_opts: opts.InitOpts = opts.InitOpts()):
super().__init__(init_opts=init_opts)
self._coordinate_system: Optional[str] = "geo"

Expand Down
2 changes: 1 addition & 1 deletion pyecharts/charts/basic_charts/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Graph(Chart):
The graph is used to represent the relational data.
"""

def __init__(self, init_opts: Union[opts.InitOpts, dict] = opts.InitOpts()):
def __init__(self, init_opts: opts.InitOpts = opts.InitOpts()):
super().__init__(init_opts=init_opts)

def add(
Expand Down
2 changes: 1 addition & 1 deletion pyecharts/charts/basic_charts/heatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class HeatMap(RectChart):
Two categories of axes must be used in rectangular coordinates.
"""

def __init__(self, init_opts: Union[opts.InitOpts, dict] = opts.InitOpts()):
def __init__(self, init_opts: opts.InitOpts = opts.InitOpts()):
super().__init__(init_opts=init_opts)
self.options.update(yAxis=[opts.AxisOpts().opts])
self.set_global_opts(visualmap_opts=opts.VisualMapOpts(orient="horizontal"))
Expand Down
2 changes: 1 addition & 1 deletion pyecharts/charts/basic_charts/line.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Line(RectChart):
with single line to show the change trend of data.
"""

def __init__(self, init_opts: Union[opts.InitOpts, dict] = opts.InitOpts()):
def __init__(self, init_opts: opts.InitOpts = opts.InitOpts()):
super().__init__(init_opts=init_opts)
self.options.update(yAxis=[opts.AxisOpts().opts])

Expand Down
2 changes: 1 addition & 1 deletion pyecharts/charts/basic_charts/liquid.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Liquid(Chart):
The liquid chart is mainly used to highlight the percentage of data.
"""

def __init__(self, init_opts: Union[opts.InitOpts, dict] = opts.InitOpts()):
def __init__(self, init_opts: opts.InitOpts = opts.InitOpts()):
super().__init__(init_opts=init_opts)
self.js_dependencies.add("echarts-liquidfill")

Expand Down
2 changes: 1 addition & 1 deletion pyecharts/charts/basic_charts/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Map(Chart):
Map are mainly used for visualization of geographic area data.
"""

def __init__(self, init_opts: Union[opts.InitOpts, dict] = opts.InitOpts()):
def __init__(self, init_opts: opts.InitOpts = opts.InitOpts()):
super().__init__(init_opts=init_opts)

def add(
Expand Down
2 changes: 1 addition & 1 deletion pyecharts/charts/basic_charts/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Parallel(Chart):
high dimensional data.
"""

def __init__(self, init_opts: Union[opts.InitOpts, dict] = opts.InitOpts()):
def __init__(self, init_opts: opts.InitOpts = opts.InitOpts()):
super().__init__(init_opts=init_opts)
self.options.update(parallel=opts.ParallelOpts().opts)

Expand Down
2 changes: 1 addition & 1 deletion pyecharts/charts/basic_charts/pie.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Pie(Chart):
the number of data points.
"""

def __init__(self, init_opts: Union[opts.InitOpts, dict] = opts.InitOpts()):
def __init__(self, init_opts: opts.InitOpts = opts.InitOpts()):
super().__init__(init_opts=init_opts)

def add(
Expand Down
2 changes: 1 addition & 1 deletion pyecharts/charts/basic_charts/polar.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Polar(Chart):
Polar coordinates can be used for scatter and polyline graphs.
"""

def __init__(self, init_opts: Union[opts.InitOpts, dict] = opts.InitOpts()):
def __init__(self, init_opts: opts.InitOpts = opts.InitOpts()):
super().__init__(init_opts=init_opts)
self.add_schema()

Expand Down
11 changes: 1 addition & 10 deletions pyecharts/charts/basic_charts/radar.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Radar(Chart):
Radar maps are mainly used to represent multivariable data.
"""

def __init__(self, init_opts: Union[opts.InitOpts, dict] = opts.InitOpts()):
def __init__(self, init_opts: opts.InitOpts = opts.InitOpts()):
super().__init__(init_opts=init_opts)

def add_schema(
Expand Down Expand Up @@ -56,15 +56,6 @@ def add(
areastyle_opts: opts.AreaStyleOpts = opts.AreaStyleOpts(),
tooltip_opts: Union[opts.TooltipOpts, dict, None] = None,
):
if isinstance(label_opts, opts.LabelOpts):
label_opts = label_opts.opts
if isinstance(linestyle_opts, opts.LineStyleOpts):
linestyle_opts = linestyle_opts.opts
if isinstance(areastyle_opts, opts.AreaStyleOpts):
areastyle_opts = areastyle_opts.opts
if isinstance(tooltip_opts, opts.TooltipOpts):
tooltip_opts = tooltip_opts.opts

self._append_legend(series_name, is_selected)
self.options.get("series").append(
{
Expand Down
2 changes: 1 addition & 1 deletion pyecharts/charts/basic_charts/sankey.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Sankey(Chart):
the intermediate process of processing, transformation to the final form.
"""

def __init__(self, init_opts: Union[opts.InitOpts, dict] = opts.InitOpts()):
def __init__(self, init_opts: opts.InitOpts = opts.InitOpts()):
super().__init__(init_opts=init_opts)

def add(
Expand Down
2 changes: 1 addition & 1 deletion pyecharts/charts/basic_charts/scatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Scatter(RectChart):
visualmap component can be used.
"""

def __init__(self, init_opts: Union[opts.InitOpts, dict] = opts.InitOpts()):
def __init__(self, init_opts: opts.InitOpts = opts.InitOpts()):
super().__init__(init_opts=init_opts)
self.options.update(yAxis=[opts.AxisOpts().opts])

Expand Down
2 changes: 1 addition & 1 deletion pyecharts/charts/basic_charts/sunburst.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Sunburst(Chart):
hierarchical relationships like rectangle tree graphs.
"""

def __init__(self, init_opts: Union[opts.InitOpts, dict] = opts.InitOpts()):
def __init__(self, init_opts: opts.InitOpts = opts.InitOpts()):
super().__init__(init_opts=init_opts)

def add(
Expand Down
2 changes: 1 addition & 1 deletion pyecharts/charts/basic_charts/themeriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ThemeRiver(Chart):
over a period of time.
"""

def __init__(self, init_opts: Union[opts.InitOpts, dict] = opts.InitOpts()):
def __init__(self, init_opts: opts.InitOpts = opts.InitOpts()):
super().__init__(init_opts=init_opts)

def add(
Expand Down
2 changes: 1 addition & 1 deletion pyecharts/charts/basic_charts/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Tree(Chart):
and right subtrees.
"""

def __init__(self, init_opts: Union[opts.InitOpts, dict] = opts.InitOpts()):
def __init__(self, init_opts: opts.InitOpts = opts.InitOpts()):
super().__init__(init_opts=init_opts)

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion pyecharts/charts/basic_charts/treemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class TreeMap(Chart):
It mainly uses area to highlight the important nodes in the hierarchy of "tree".
"""

def __init__(self, init_opts: Union[opts.InitOpts, dict] = opts.InitOpts()):
def __init__(self, init_opts: opts.InitOpts = opts.InitOpts()):
super().__init__(init_opts=init_opts)

def add(
Expand Down
2 changes: 1 addition & 1 deletion pyecharts/charts/basic_charts/wordcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class WordCloud(Chart):
appear frequently in the text.
"""

def __init__(self, init_opts: Union[opts.InitOpts, dict] = opts.InitOpts()):
def __init__(self, init_opts: opts.InitOpts = opts.InitOpts()):
super().__init__(init_opts=init_opts)
self.js_dependencies.add("echarts-wordcloud")

Expand Down
6 changes: 3 additions & 3 deletions pyecharts/charts/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Chart(Base):
`Chart`类是所有非自定义类的基类,继承自 `Base` 类
"""

def __init__(self, init_opts: Union[opts.InitOpts, dict] = opts.InitOpts()):
def __init__(self, init_opts: opts.InitOpts = opts.InitOpts()):
super().__init__(init_opts=init_opts)
self.colors = (
"#c23531 #2f4554 #61a0a8 #d48265 #749f83 #ca8622 #bda29a #6e7074 "
Expand Down Expand Up @@ -198,12 +198,12 @@ class Chart3D(Chart):
`Chart3D`类是所有 3D 类图表的基类,继承自 `Chart` 类
"""

def __init__(self, init_opts: Union[opts.InitOpts, dict] = opts.InitOpts()):
def __init__(self, init_opts: opts.InitOpts = opts.InitOpts()):
init_opts.renderer = RenderType.CANVAS
super().__init__(init_opts)
self.js_dependencies.add("echarts-gl")
self.options.update(visualMap=opts.VisualMapOpts().opts)
self._3d_chart_type = None # 3d chart type, don't use it directly
self._3d_chart_type: Optional[str] = None # 3d chart type,don't use it directly

def add(
self,
Expand Down
2 changes: 1 addition & 1 deletion pyecharts/charts/composite_charts/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Grid(Base):
and scatter chart (bubble chart) can be drawn in grid.
"""

def __init__(self, init_opts: Union[opts.InitOpts, dict] = opts.InitOpts()):
def __init__(self, init_opts: opts.InitOpts = opts.InitOpts()):
super().__init__(init_opts=init_opts)
self.options: Optional[dict] = None
self._axis_index: int = 0
Expand Down
6 changes: 3 additions & 3 deletions pyecharts/charts/composite_charts/timeline.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
from ... import options as opts
from ...charts.chart import Base
from ...commons.types import Numeric, Optional, Union
from ...commons.types import Numeric, Optional, Union, Sequence


class Timeline(Base):
"""
`Timeline` provides functions like switching and playing between multiple charts.
"""

def __init__(self, init_opts: Union[opts.InitOpts, dict] = opts.InitOpts()):
def __init__(self, init_opts: opts.InitOpts = opts.InitOpts()):
super().__init__(init_opts=init_opts)
self.options = {"baseOption": {"series": [], "timeline": {}}, "options": []}
self.add_schema()
self._time_points = []
self._time_points: Sequence = []

def add_schema(
self,
Expand Down
2 changes: 1 addition & 1 deletion pyecharts/components/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(
self.page_title = page_title
self.js_host = js_host
self.js_dependencies: OrderedSet = OrderedSet("bulma")
self._charts = []
self._charts: Sequence = []

def add(self, headers: Sequence, rows: Sequence, attributes: Optional[dict] = None):

Expand Down
2 changes: 1 addition & 1 deletion pyecharts/render/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,4 @@ def save_as(image_data: bytes, output_name: str, file_type: str):
b.paste(m, mask=m.split()[3])
b.save(output_name, file_type, quality=100)
except ModuleNotFoundError:
raise Exception("Please install PIL for % image type" % file_type)
raise Exception("Please install PIL for {} image type".format(file_type))

0 comments on commit d7bb09a

Please sign in to comment.