From 8b9c5a4e7346a67c014d489089305304df984602 Mon Sep 17 00:00:00 2001 From: sepandhaghighi Date: Thu, 9 Jul 2026 23:32:20 +0330 Subject: [PATCH 1/4] feat : add _validate_convert function --- xnum/functions.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/xnum/functions.py b/xnum/functions.py index d376050..55badad 100644 --- a/xnum/functions.py +++ b/xnum/functions.py @@ -32,9 +32,9 @@ def translate_digit(char: str, target: NumeralSystem) -> str: return char -def convert(text: str, target: NumeralSystem, source: NumeralSystem = NumeralSystem.AUTO) -> str: +def _validate_convert(text: Any, target: Any, source: Any) -> bool: """ - Convert function. + Validate convert inputs. :param text: input text :param target: target numeral system @@ -48,7 +48,18 @@ def convert(text: str, target: NumeralSystem, source: NumeralSystem = NumeralSys raise ValueError(INVALID_TARGET_MESSAGE2) if not isinstance(source, NumeralSystem): raise ValueError(INVALID_SOURCE_MESSAGE) + return True + +def convert(text: str, target: NumeralSystem, source: NumeralSystem = NumeralSystem.AUTO) -> str: + """ + Convert function. + + :param text: input text + :param target: target numeral system + :param source: source numeral system + """ + _validate_convert(text=text, target=target, source=source) all_digits = list(ALL_DIGIT_MAPS.keys()) all_digits.sort(key=len, reverse=True) pattern = r"(?:{})".format("|".join(re.escape(digit) for digit in all_digits)) From 0aa3f1d7a8794d8442ee33ed64cc2668c45238f8 Mon Sep 17 00:00:00 2001 From: sepandhaghighi Date: Thu, 9 Jul 2026 23:32:46 +0330 Subject: [PATCH 2/4] doc : update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e1636cb..1ee383d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Added - Nag Mundari numeral system - `available_systems` function +- `_validate_convert` function ### Changed - `README.md` updated - Test system modified From cbf4e54fd3965d60ac55ccc6c45c62a2e26c4688 Mon Sep 17 00:00:00 2001 From: sepandhaghighi Date: Thu, 9 Jul 2026 23:33:12 +0330 Subject: [PATCH 3/4] fix : autopep8 --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index 25b6a86..c864b88 100644 --- a/setup.py +++ b/setup.py @@ -5,6 +5,7 @@ except ImportError: from distutils.core import setup + def read_description() -> str: """Read README.md and CHANGELOG.md.""" try: From f8980485f15abff04228c05b46d43471e84841d7 Mon Sep 17 00:00:00 2001 From: sepandhaghighi Date: Thu, 9 Jul 2026 23:34:55 +0330 Subject: [PATCH 4/4] fix : add missing imports --- xnum/functions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xnum/functions.py b/xnum/functions.py index 55badad..b92303e 100644 --- a/xnum/functions.py +++ b/xnum/functions.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """XNum functions.""" import re -from typing import Match, List +from typing import Match, List, Any from .params import NumeralSystem, NUMERAL_MAPS, ALL_DIGIT_MAPS from .params import INVALID_SOURCE_MESSAGE, INVALID_TEXT_MESSAGE from .params import INVALID_TARGET_MESSAGE1, INVALID_TARGET_MESSAGE2