Add: mypy checker (#1106)

This commit is contained in:
陈键冬 2019-05-13 13:43:50 +08:00 committed by GitHub
parent 002c578b0c
commit d7bb09a71b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
31 changed files with 39 additions and 45 deletions

3
.gitignore vendored
View File

@ -99,3 +99,6 @@ ENV/
# example
example/*.png
example/*.html
# mypy
.mypy_cache/

View File

@ -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

View File

@ -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])

View File

@ -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

View File

@ -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])

View File

@ -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)

View File

@ -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])

View File

@ -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(

View File

@ -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(

View File

@ -9,7 +9,7 @@ from ...globals import ChartType, TooltipFormatterType
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
@ -27,7 +27,7 @@ class GeoChartBase(Chart):
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]
@ -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"

View File

@ -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(

View File

@ -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"))

View File

@ -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])

View File

@ -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")

View File

@ -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(

View File

@ -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)

View File

@ -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(

View File

@ -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()

View File

@ -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(
@ -56,15 +56,6 @@ class Radar(Chart):
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(
{

View File

@ -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(

View File

@ -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])

View File

@ -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(

View File

@ -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(

View File

@ -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

View File

@ -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(

View File

@ -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")

View File

@ -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 "
@ -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,

View File

@ -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

View File

@ -1,6 +1,6 @@
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):
@ -8,11 +8,11 @@ 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,

View File

@ -19,7 +19,7 @@ class Table:
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):

View File

@ -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))