Skip to content

Commit

Permalink
Merge pull request #279 from kairu-ms/fix-default-float-value
Browse files Browse the repository at this point in the history
Convert int value to float for FloatArg default and blank value.
  • Loading branch information
kairu-ms authored Aug 15, 2023
2 parents e63ebb4 + 3beee08 commit 54c8766
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/aaz_dev/command/model/configuration/_arg.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,8 +614,12 @@ def _reformat_base(self, **kwargs):
self.enum.reformat(**kwargs)
if self.blank:
if not isinstance(self.blank.value, float) and not (self.nullable and self.blank.value is None):
raise exceptions.VerificationError(
f"Invalid blank value", details=f"'{self.blank.value}' is not a valid float arg value")
if isinstance(self.blank.value, int):
# frontend will pass an int value when it doesn't have decimal part
self.blank.value = float(self.blank.value)
else:
raise exceptions.VerificationError(
f"Invalid blank value", details=f"'{self.blank.value}' is not a valid float arg value")


class CMDFloatArg(CMDFloatArgBase, CMDArg):
Expand All @@ -624,8 +628,12 @@ def _reformat(self, **kwargs):
super()._reformat(**kwargs)
if self.default:
if not isinstance(self.default.value, float) and not (self.nullable and self.default.value is None):
raise exceptions.VerificationError(
f"Invalid default value", details=f"'{self.default.value}' is not a valid float arg value")
if isinstance(self.default.value, int):
# frontend will pass an int value when it doesn't have decimal part
self.default.value = float(self.default.value)
else:
raise exceptions.VerificationError(
f"Invalid default value", details=f"'{self.default.value}' is not a valid float arg value")


# float32
Expand Down

0 comments on commit 54c8766

Please sign in to comment.