|
13 | 13 |
|
14 | 14 |
|
15 | 15 | class SpecParser: |
16 | | - |
17 | 16 | def __init__( |
18 | 17 | self, |
19 | 18 | renderer: Literal["widget", "jsdom"] = "widget", |
@@ -41,11 +40,7 @@ def spec(self): |
41 | 40 | return self._spec |
42 | 41 |
|
43 | 42 | def set_spec(self, value: dict, *, force_figure: bool = False): |
44 | | - if ( |
45 | | - "pyobsplot-type" in value |
46 | | - and value["pyobsplot-type"] == "function" |
47 | | - and value["module"] == "Plot" |
48 | | - ): |
| 43 | + if "pyobsplot-type" in value and value["pyobsplot-type"] == "function" and value["module"] == "Plot": |
49 | 44 | value = {"marks": [value]} |
50 | 45 | if force_figure: |
51 | 46 | value["figure"] = True |
@@ -134,11 +129,7 @@ def parse(self, spec: Any) -> Any: |
134 | 129 | if isinstance(spec, str) and spec[0:28] == '{"type": "FeatureCollection"': |
135 | 130 | spec = json.loads(spec) |
136 | 131 | # If Geojson as dict, handle caching, don't parse, add type and returns as is |
137 | | - if ( |
138 | | - isinstance(spec, dict) |
139 | | - and "type" in spec |
140 | | - and spec["type"] == "FeatureCollection" |
141 | | - ): |
| 132 | + if isinstance(spec, dict) and "type" in spec and spec["type"] == "FeatureCollection": |
142 | 133 | index = self.cache_index(spec) |
143 | 134 | if index is None: |
144 | 135 | self.data.append(spec) |
@@ -184,13 +175,10 @@ def parse(self, spec: Any) -> Any: |
184 | 175 | return {"pyobsplot-type": "datetime", "value": spec.isoformat()} |
185 | 176 | # Handling of JavaScript methods as objects, such as "Math.sin" |
186 | 177 | # Manually call the parsed result and add a special "function-object" type |
187 | | - if ( |
188 | | - callable(spec) |
189 | | - and isinstance(spec(), dict) |
190 | | - and spec()["pyobsplot-type"] == "function" |
191 | | - ): |
| 178 | + if callable(spec): |
192 | 179 | out = spec() |
193 | | - out["pyobsplot-type"] = "function-object" |
| 180 | + if isinstance(out, dict) and out["pyobsplot-type"] == "function": |
| 181 | + out["pyobsplot-type"] = "function-object" |
194 | 182 | return out |
195 | 183 | return spec |
196 | 184 |
|
|
0 commit comments