Skip to content

Commit 35241ef

Browse files
add regular expressions for float and int
and use them as fallback
1 parent 13c99b1 commit 35241ef

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

acclimatise/model.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,14 +371,17 @@ def capital(self):
371371
)
372372

373373

374-
int_re = re.compile("(int(eger)?)|size|length|max|min", flags=re.IGNORECASE)
374+
int_re = re.compile("(int(eger)?)|size|length|max|min|num(ber)?", flags=re.IGNORECASE)
375375
str_re = re.compile("str(ing)?", flags=re.IGNORECASE)
376376
float_re = re.compile("float|decimal", flags=re.IGNORECASE)
377377
bool_re = re.compile("bool(ean)?", flags=re.IGNORECASE)
378378
file_re = re.compile("file|path", flags=re.IGNORECASE)
379379
dir_re = re.compile("folder|directory", flags=re.IGNORECASE)
380380

381381
default_re = re.compile("default(?: value)?(?:[:=] ?| )([^ )\]]+)", flags=re.IGNORECASE)
382+
float_re = re.compile('[+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)', flags=re.IGNORECASE)
383+
int_re = re.compile('[+-]?([0-9]+[^.0-9])', flags=re.IGNORECASE)
384+
382385

383386
def infer_type(string) -> typing.Optional[cli_types.CliType]:
384387
"""
@@ -403,6 +406,10 @@ def infer_type(string) -> typing.Optional[cli_types.CliType]:
403406
return cli_types.CliDir(default = default)
404407
elif str_re.match(string):
405408
return cli_types.CliString(default = default)
409+
elif float_re.search(string) and not int_re.search(string):
410+
return cli_types.CliFloat(default = default)
411+
elif not int_re.search(string) and int_re.search(string):
412+
return cli_types.CliInteger(default = default)
406413
else:
407414
return cli_types.CliString(default = default)
408415

0 commit comments

Comments
 (0)