Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Nanguage committed Sep 13, 2022
1 parent 1c5adc9 commit 6df3613
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
10 changes: 7 additions & 3 deletions oneface/arg.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def check(self, val):
if not self.type_checker(val, self.type):
raise TypeError(
f"Input value {val} is not in valid type({self.type})")
if (self.range is not None) and (self.range_checker is not None):
if (self.range_checker is not None):
if (not self.range_checker(val, self.range)):
raise ValueError(f"Input value {val} is not in a valid range.")

Expand All @@ -56,11 +56,15 @@ def register_type_check(cls, type, checker=None):


# register basic types
def _check_number_in_range(v, range):
return (range is None) or (range[0] <= v <= range[1])


Arg.register_type_check(Empty, lambda v, range: True)
Arg.register_type_check(str)
Arg.register_range_check(int, lambda v, range: range[0] <= v <= range[1])
Arg.register_range_check(int, _check_number_in_range)
Arg.register_type_check(int)
Arg.register_range_check(float, lambda v, range: range[0] <= v <= range[1])
Arg.register_range_check(float, _check_number_in_range)
Arg.register_type_check(float)
Arg.register_type_check(bool)

Expand Down
8 changes: 4 additions & 4 deletions tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


def test_selection():
@one
@one(print_args=False)
def func1(a: Arg(Selection, ["a", 2, 3])):
print(a)
return a
Expand All @@ -18,7 +18,7 @@ def func1(a: Arg(Selection, ["a", 2, 3])):


def test_subset():
@one
@one(print_args=False)
def func1(s: Arg(SubSet, [1,2,3])):
print(s)
return s
Expand All @@ -31,7 +31,7 @@ def func1(s: Arg(SubSet, [1,2,3])):


def test_inputpath():
@one
@one(print_args=False)
def func1(s: Arg(InputPath)):
print(s)
return s
Expand All @@ -46,7 +46,7 @@ def func1(s: Arg(InputPath)):


def test_outputpath():
@one
@one(print_args=False)
def func1(s: Arg(OutputPath)):
print(s)
return s
Expand Down

0 comments on commit 6df3613

Please sign in to comment.