Skip to content

Commit 816b3a8

Browse files
committed
fix lint/typing errors
1 parent b31ef7d commit 816b3a8

File tree

1 file changed

+28
-32
lines changed

1 file changed

+28
-32
lines changed

planet/cli/data.py

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"""The Planet Data CLI."""
1515
from datetime import datetime
1616
import json
17-
from typing import List, Union
17+
from typing import List, Optional
1818
from contextlib import asynccontextmanager
1919

2020
import click
@@ -138,97 +138,93 @@ class DateTimeType(click.ParamType):
138138
name = 'datetime'
139139

140140
def convert(self, value, param, ctx) -> datetime:
141-
if isinstance(value, datetime):
142-
return value
143-
else:
141+
if not isinstance(value, datetime):
144142
try:
145-
return io.str_to_datetime(value)
143+
value = io.str_to_datetime(value)
146144
except exceptions.PlanetError as e:
147145
self.fail(str(e))
148146

147+
return value
148+
149149

150150
class CommaSeparatedString(click.types.StringParamType):
151151
"""A list of strings that is extracted from a comma-separated string."""
152152

153153
def convert(self, value, param, ctx) -> List[str]:
154154
value = super().convert(value, param, ctx)
155155

156-
if isinstance(value, list):
157-
return value
158-
else:
159-
return [part.strip() for part in value.split(",")]
156+
if not isinstance(value, list):
157+
value = [part.strip() for part in value.split(",")]
158+
159+
return value
160160

161161

162-
class CommaSeparatedFloat(CommaSeparatedString):
162+
class CommaSeparatedFloat(click.types.StringParamType):
163163
"""A list of floats that is extracted from a comma-separated string."""
164164
name = 'VALUE'
165165

166-
def convert(self, value, param, ctx):
167-
values = super().convert(value, param, ctx)
166+
def convert(self, value, param, ctx) -> List[float]:
167+
values = CommaSeparatedString().convert(value, param, ctx)
168168

169169
try:
170-
return [float(v) for v in values]
170+
ret = [float(v) for v in values]
171171
except ValueError:
172172
self.fail(f'Cound not convert all entries in {value} to float.')
173173

174+
return ret
175+
174176

175-
def assets_to_filter(ctx, param, assets: str) -> dict:
176-
if assets:
177-
# TODO: validate and normalize
178-
return data_filter.asset_filter(assets)
177+
def assets_to_filter(ctx, param, assets: List[str]) -> Optional[dict]:
178+
# TODO: validate and normalize
179+
return data_filter.asset_filter(assets) if assets else None
179180

180181

181-
def date_range_to_filter(ctx, param, values) -> Union[List[dict], None]:
182+
def date_range_to_filter(ctx, param, values) -> Optional[List[dict]]:
182183

183184
def _func(obj):
184185
field, comp, value = obj
185186
kwargs = {'field_name': field, comp: value}
186187
return data_filter.date_range_filter(**kwargs)
187188

188-
if values:
189-
return [_func(v) for v in values]
189+
return [_func(v) for v in values] if values else None
190190

191191

192-
def range_to_filter(ctx, param, values) -> Union[List[dict], None]:
192+
def range_to_filter(ctx, param, values) -> Optional[List[dict]]:
193193

194194
def _func(obj):
195195
field, comp, value = obj
196196
kwargs = {'field_name': field, comp: value}
197197
return data_filter.range_filter(**kwargs)
198198

199-
if values:
200-
return [_func(v) for v in values]
199+
return [_func(v) for v in values] if values else None
201200

202201

203-
def update_to_filter(ctx, param, values) -> Union[List[dict], None]:
202+
def update_to_filter(ctx, param, values) -> Optional[List[dict]]:
204203

205204
def _func(obj):
206205
field, comp, value = obj
207206
kwargs = {'field_name': field, comp: value}
208207
return data_filter.update_filter(**kwargs)
209208

210-
if values:
211-
return [_func(v) for v in values]
209+
return [_func(v) for v in values] if values else None
212210

213211

214-
def number_in_to_filter(ctx, param, values) -> Union[dict, None]:
212+
def number_in_to_filter(ctx, param, values) -> Optional[List[dict]]:
215213

216214
def _func(obj):
217215
field, values = obj
218216
return data_filter.number_in_filter(field_name=field, values=values)
219217

220-
if values:
221-
return [_func(v) for v in values]
218+
return [_func(v) for v in values] if values else None
222219

223220

224-
def string_in_to_filter(ctx, param, values) -> Union[dict, None]:
221+
def string_in_to_filter(ctx, param, values) -> Optional[List[dict]]:
225222

226223
def _func(obj):
227224
field, values = obj
228225
return data_filter.string_in_filter(field_name=field, values=values)
229226

230-
if values:
231-
return [_func(v) for v in values]
227+
return [_func(v) for v in values] if values else None
232228

233229

234230
@data.command()

0 commit comments

Comments
 (0)