From 073f81e5ca0567f380429555352f8085f00e1295 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=95=D0=B2=D0=B3=D0=B5=D0=BD=D0=B8=D0=B9=20=D0=91=D0=BB?= =?UTF-8?q?=D0=B8=D0=BD=D0=BE=D0=B2?= Date: Thu, 6 Nov 2025 20:44:21 +0300 Subject: [PATCH 1/7] =?UTF-8?q?Support=20+=E2=88=9E=20in=20from=5Fstring?= =?UTF-8?q?=20for=20float=20conversion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simtypes/from_string.py | 2 +- tests/units/test_from_string.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/simtypes/from_string.py b/simtypes/from_string.py index 7d2c4ac..d351744 100644 --- a/simtypes/from_string.py +++ b/simtypes/from_string.py @@ -44,7 +44,7 @@ def from_string(value: str, expected_type: Type[ExpectedType]) -> ExpectedType: raise TypeError(f'The string "{value}" cannot be interpreted as an integer.') from e elif expected_type is float: - if value == '∞': + if value == '∞' or value == '+∞': value = 'inf' elif value == '-∞': value = '-inf' diff --git a/tests/units/test_from_string.py b/tests/units/test_from_string.py index 814fd2b..e2f7ee0 100644 --- a/tests/units/test_from_string.py +++ b/tests/units/test_from_string.py @@ -85,6 +85,7 @@ def test_get_float_value(): assert from_string('INF', float) == inf assert from_string('-INF', float) == -inf assert from_string('∞', float) == inf + assert from_string('+∞', float) == inf assert from_string('-∞', float) == -inf assert isnan(from_string('nan', float)) From a659751c69bfd1b42eb2754b13c668a7d7fd5f9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=95=D0=B2=D0=B3=D0=B5=D0=BD=D0=B8=D0=B9=20=D0=91=D0=BB?= =?UTF-8?q?=D0=B8=D0=BD=D0=BE=D0=B2?= Date: Thu, 6 Nov 2025 20:48:07 +0300 Subject: [PATCH 2/7] Support Any type in from_string by returning input unchanged --- simtypes/from_string.py | 5 ++++- tests/units/test_from_string.py | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/simtypes/from_string.py b/simtypes/from_string.py index d351744..ff2dbc6 100644 --- a/simtypes/from_string.py +++ b/simtypes/from_string.py @@ -1,4 +1,4 @@ -from typing import Type, get_origin +from typing import Type, Any, get_origin from json import loads, JSONDecodeError from inspect import isclass @@ -10,6 +10,9 @@ def from_string(value: str, expected_type: Type[ExpectedType]) -> ExpectedType: if not isinstance(value, str): raise ValueError(f'You can only pass a string as a string. You passed {type(value).__name__}.') + if expected_type is Any: + return value + origin_type = get_origin(expected_type) if any(x in (dict, list, tuple) for x in (expected_type, origin_type)): diff --git a/tests/units/test_from_string.py b/tests/units/test_from_string.py index e2f7ee0..b8056d8 100644 --- a/tests/units/test_from_string.py +++ b/tests/units/test_from_string.py @@ -1,4 +1,5 @@ from math import inf, isnan +from typing import Any import pytest from full_match import match @@ -287,3 +288,15 @@ def test_get_dict_value(dict_type, subscribable_list_type, subscribable_dict_typ with pytest.raises(TypeError, match=match('The string "{"lol": {"kek": "kek"}}" cannot be interpreted as a dict of the specified format.')): from_string('{"lol": {"kek": "kek"}}', subscribable_dict_type[str, subscribable_dict_type[int, str]]) + + +@pytest.mark.parametrize( + ['string'], + [ + ('{"lol": "kek"}',), + ('1',), + ('kek',), + ], +) +def test_get_any(string): + from_string(string, Any) == string From 3ce98b48823581e8845effa63d0437828a02b222 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=95=D0=B2=D0=B3=D0=B5=D0=BD=D0=B8=D0=B9=20=D0=91=D0=BB?= =?UTF-8?q?=D0=B8=D0=BD=D0=BE=D0=B2?= Date: Thu, 6 Nov 2025 20:49:28 +0300 Subject: [PATCH 3/7] Fix assertion syntax in test_get_any --- tests/units/test_from_string.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/units/test_from_string.py b/tests/units/test_from_string.py index b8056d8..238b0c1 100644 --- a/tests/units/test_from_string.py +++ b/tests/units/test_from_string.py @@ -299,4 +299,4 @@ def test_get_dict_value(dict_type, subscribable_list_type, subscribable_dict_typ ], ) def test_get_any(string): - from_string(string, Any) == string + assert from_string(string, Any) == string From 600e830d5136b7a5bbf9234e42c99b832d4e3b8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=95=D0=B2=D0=B3=D0=B5=D0=BD=D0=B8=D0=B9=20=D0=91=D0=BB?= =?UTF-8?q?=D0=B8=D0=BD=D0=BE=D0=B2?= Date: Thu, 6 Nov 2025 20:49:37 +0300 Subject: [PATCH 4/7] Add example showing Any interpreted as string --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 148df37..5aacfe6 100644 --- a/README.md +++ b/README.md @@ -191,6 +191,8 @@ print(from_string('-inf', float)) # strings print(from_string('I am the danger', str)) #> "I am the danger" +print(from_string('I am the danger', Any)) # Any is interpreted as a string. +#> "I am the danger" # bools print(from_string('yes', bool)) From 73c599fb319528b0b1618242334df5ac74fb0549 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=95=D0=B2=D0=B3=D0=B5=D0=BD=D0=B8=D0=B9=20=D0=91=D0=BB?= =?UTF-8?q?=D0=B8=D0=BD=D0=BE=D0=B2?= Date: Thu, 6 Nov 2025 20:49:57 +0300 Subject: [PATCH 5/7] New version tag --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 93bde3b..fb8b7c6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "simtypes" -version = "0.0.5" +version = "0.0.6" authors = [{ name = "Evgeniy Blinov", email = "zheni-b@yandex.ru" }] description = 'Type checking in runtime without stupid games' readme = "README.md" From 1224f1e78b87d284d6cef509ad3f8076e461c601 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=95=D0=B2=D0=B3=D0=B5=D0=BD=D0=B8=D0=B9=20=D0=91=D0=BB?= =?UTF-8?q?=D0=B8=D0=BD=D0=BE=D0=B2?= Date: Thu, 6 Nov 2025 20:52:35 +0300 Subject: [PATCH 6/7] Add type ignore comment for Any return --- simtypes/from_string.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simtypes/from_string.py b/simtypes/from_string.py index ff2dbc6..e1751b7 100644 --- a/simtypes/from_string.py +++ b/simtypes/from_string.py @@ -11,7 +11,7 @@ def from_string(value: str, expected_type: Type[ExpectedType]) -> ExpectedType: raise ValueError(f'You can only pass a string as a string. You passed {type(value).__name__}.') if expected_type is Any: - return value + return value # type: ignore[return-value] origin_type = get_origin(expected_type) From c29d44bd76478e7612e3d4aae82af2b5d476aa77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=95=D0=B2=D0=B3=D0=B5=D0=BD=D0=B8=D0=B9=20=D0=91=D0=BB?= =?UTF-8?q?=D0=B8=D0=BD=D0=BE=D0=B2?= Date: Thu, 6 Nov 2025 20:59:16 +0300 Subject: [PATCH 7/7] Update Hits-of-Code badge to exclude docs directory --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5aacfe6..b9b1716 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [![Downloads](https://static.pepy.tech/badge/simtypes)](https://pepy.tech/project/simtypes) [![Coverage Status](https://coveralls.io/repos/github/pomponchik/simtypes/badge.svg?branch=main)](https://coveralls.io/github/pomponchik/simtypes?branch=main) [![Lines of code](https://sloc.xyz/github/pomponchik/simtypes/?category=code)](https://github.com/boyter/scc/) -[![Hits-of-Code](https://hitsofcode.com/github/pomponchik/simtypes?branch=main)](https://hitsofcode.com/github/pomponchik/simtypes/view?branch=main) +[![Hits-of-Code](https://hitsofcode.com/github/pomponchik/simtypes?branch=main&label=Hits-of-Code&exclude=docs/)](https://hitsofcode.com/github/pomponchik/simtypes/view?branch=main) [![Test-Package](https://github.com/pomponchik/simtypes/actions/workflows/tests_and_coverage.yml/badge.svg)](https://github.com/pomponchik/simtypes/actions/workflows/tests_and_coverage.yml) [![Python versions](https://img.shields.io/pypi/pyversions/simtypes.svg)](https://pypi.python.org/pypi/simtypes) [![PyPI version](https://badge.fury.io/py/simtypes.svg)](https://badge.fury.io/py/simtypes)