Skip to content

Commit

Permalink
int value is allowed for float type
Browse files Browse the repository at this point in the history
  • Loading branch information
y1xiaoc committed Apr 21, 2023
1 parent debc06b commit 829e19b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
13 changes: 8 additions & 5 deletions dargs/dargs.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
"""


from typing import Union, Any, List, Dict, Iterable, Optional, Callable
from textwrap import indent
import fnmatch
import json
import re
from copy import deepcopy
from enum import Enum
import fnmatch, re
import json
from numbers import Real
from textwrap import indent
from typing import Any, Callable, Dict, Iterable, List, Optional, Union


INDENT = " " # doc is indented by four spaces
Expand Down Expand Up @@ -412,7 +414,8 @@ def _check_exist(self, argdict: dict, path=None):
)

def _check_data(self, value: Any, path=None):
if not isinstance(value, self.dtype):
if not (isinstance(value, self.dtype)
or (float in self.dtype and isinstance(value, Real))):
raise ArgumentTypeError(
path,
f"key `{self.name}` gets wrong value type, "
Expand Down
3 changes: 3 additions & 0 deletions tests/test_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ def test_name_type(self):
# special handle of None
ca = Argument("key1", [int, None])
ca.check({"key1": None})
# special handel of int and float
ca = Argument("key1", float)
ca.check({"key1": 1})
# optional case
ca = Argument("key1", int, optional=True)
ca.check({})
Expand Down

0 comments on commit 829e19b

Please sign in to comment.