Skip to content

Commit fd58ad4

Browse files
author
irinaschubert
authored
fix(boolean-values): allow 0 and 1 as boolean values (DEV-251) (#131)
* allow 0 and 1 as boolean values * add documentation * remove complexity * use f-string for error message
1 parent 6a40fc6 commit fd58ad4

2 files changed

Lines changed: 7 additions & 8 deletions

File tree

‎docs/dsp-tools-xmlupload.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ Attributes:
696696

697697
#### `<boolean>`
698698

699-
The `<boolean>` element must contain the string "true" or "false", or the numeral 1 or 0.
699+
The `<boolean>` element must contain the string "true" or "false", or the numeral 1 (true) or 0 (false).
700700

701701
Attributes:
702702

‎knora/dsplib/models/value.py‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -601,18 +601,17 @@ def __init__(self,
601601
iri: Optional[str] = None,
602602
ark_url: Optional[str] = None,
603603
vark_url: Optional[str] = None):
604+
604605
if type(value) is bool:
605606
self._value = value
606-
607-
elif type(value) is str:
608-
if value.upper() == 'TRUE':
607+
else:
608+
if value == 1 or value.upper() == 'TRUE' or value == '1':
609609
self._value = True
610-
elif value.upper() == 'FALSE':
610+
elif value == 0 or value.upper() == 'FALSE' or value == '0':
611611
self._value = False
612612
else:
613-
raise BaseError("Invalid boolean format! " + str(value))
614-
elif type(value) is int:
615-
self._value = False if value == 0 else True
613+
raise BaseError(f"ERROR Invalid boolean format {value}!")
614+
616615
super().__init__(iri=iri,
617616
comment=comment,
618617
permissions=permissions,

0 commit comments

Comments
 (0)