Skip to content

Commit 65283e9

Browse files
committed
Cleanup
Signed-off-by: martinRenou <[email protected]>
1 parent 68e167c commit 65283e9

File tree

1 file changed

+23
-28
lines changed

1 file changed

+23
-28
lines changed

ipygany/ipygany.py

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -474,43 +474,38 @@ def _validate_input_impl(self, value):
474474
if len(value) != 3:
475475
raise TraitError('input is of dimension {} but expected input dimension is {}'.format(len(value), 3))
476476

477-
inputs = []
478-
479477
# Check all elements in the tuple
480-
for el in value:
481-
# Component selection by name
482-
if isinstance(el, (tuple, list)):
483-
if len(el) != 2:
484-
raise TraitError('{} is not a valid component'.format(el))
478+
return tuple(self._validate_input_component(el) for el in value)
485479

486-
try:
487-
self[el[0], el[1]]
488-
except KeyError:
489-
raise TraitError('{} is not a valid component'.format(el))
480+
raise TraitError('{} is not a valid input'.format(value))
490481

491-
inputs.append(el)
492-
continue
482+
def _validate_input_component(self, value):
483+
# Component selection by name
484+
if isinstance(value, (tuple, list)):
485+
if len(value) != 2:
486+
raise TraitError('{} is not a valid component'.format(value))
493487

494-
# Data selection by name
495-
if isinstance(el, str):
496-
try:
497-
data = self[el]
498-
except KeyError:
499-
raise TraitError('{} is not a valid component'.format(el))
488+
try:
489+
self[value[0], value[1]]
490+
except KeyError:
491+
raise TraitError('{} is not a valid component'.format(value))
500492

501-
if data.dim != 1:
502-
raise TraitError('{} is ambiguous, please select a component'.format(el))
493+
return value
503494

504-
inputs.append((data.name, data.components[0].name))
505-
continue
495+
# Data selection by name
496+
if isinstance(value, str):
497+
try:
498+
data = self[value]
499+
except KeyError:
500+
raise TraitError('{} is not a valid data'.format(value))
506501

507-
if isinstance(el, (float, int)):
508-
inputs.append(el)
509-
continue
502+
if data.dim != 1:
503+
raise TraitError('{} is ambiguous, please select a component'.format(value))
510504

511-
raise TraitError('{} is not a valid input'.format(el))
505+
return (data.name, data.components[0].name)
512506

513-
return tuple(inputs)
507+
if isinstance(value, (float, int)):
508+
return value
514509

515510
raise TraitError('{} is not a valid input'.format(value))
516511

0 commit comments

Comments
 (0)