Skip to content

Commit fac9a91

Browse files
Validation (#198)
* feat : add _validate_convert function * doc : update CHANGELOG.md * fix : autopep8 * fix : add missing imports
1 parent 158af6b commit fac9a91

3 files changed

Lines changed: 16 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
88
### Added
99
- Nag Mundari numeral system
1010
- `available_systems` function
11+
- `_validate_convert` function
1112
### Changed
1213
- `README.md` updated
1314
- Test system modified

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
except ImportError:
66
from distutils.core import setup
77

8+
89
def read_description() -> str:
910
"""Read README.md and CHANGELOG.md."""
1011
try:

xnum/functions.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
22
"""XNum functions."""
33
import re
4-
from typing import Match, List
4+
from typing import Match, List, Any
55
from .params import NumeralSystem, NUMERAL_MAPS, ALL_DIGIT_MAPS
66
from .params import INVALID_SOURCE_MESSAGE, INVALID_TEXT_MESSAGE
77
from .params import INVALID_TARGET_MESSAGE1, INVALID_TARGET_MESSAGE2
@@ -32,9 +32,9 @@ def translate_digit(char: str, target: NumeralSystem) -> str:
3232
return char
3333

3434

35-
def convert(text: str, target: NumeralSystem, source: NumeralSystem = NumeralSystem.AUTO) -> str:
35+
def _validate_convert(text: Any, target: Any, source: Any) -> bool:
3636
"""
37-
Convert function.
37+
Validate convert inputs.
3838
3939
:param text: input text
4040
:param target: target numeral system
@@ -48,7 +48,18 @@ def convert(text: str, target: NumeralSystem, source: NumeralSystem = NumeralSys
4848
raise ValueError(INVALID_TARGET_MESSAGE2)
4949
if not isinstance(source, NumeralSystem):
5050
raise ValueError(INVALID_SOURCE_MESSAGE)
51+
return True
52+
5153

54+
def convert(text: str, target: NumeralSystem, source: NumeralSystem = NumeralSystem.AUTO) -> str:
55+
"""
56+
Convert function.
57+
58+
:param text: input text
59+
:param target: target numeral system
60+
:param source: source numeral system
61+
"""
62+
_validate_convert(text=text, target=target, source=source)
5263
all_digits = list(ALL_DIGIT_MAPS.keys())
5364
all_digits.sort(key=len, reverse=True)
5465
pattern = r"(?:{})".format("|".join(re.escape(digit) for digit in all_digits))

0 commit comments

Comments
 (0)