Skip to content

Commit

Permalink
feat: Add python 3.11 support.
Browse files Browse the repository at this point in the history
Update evaluation functions to not coerce integers to floating point
numbers when not necessary.
  • Loading branch information
feanil committed Apr 3, 2024
1 parent 5a6acb1 commit 19dfd32
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion calc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

from .calc import *

__version__ = '3.0.1'
__version__ = '3.1.0'
10 changes: 7 additions & 3 deletions calc/calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,11 @@ def eval_number(parse_result):
e.g. [ '7.13', 'e', '3' ] -> 7130
Calls super_float above.
"""
return super_float("".join(parse_result))
for item in parse_result:
if "." in item or "e" in item or "E" in item:
return super_float("".join(parse_result))

return int("".join(parse_result))


def eval_atom(parse_result):
Expand Down Expand Up @@ -185,7 +189,7 @@ def eval_sum(parse_result):
Allow a leading + or -.
"""
total = 0.0
total = 0
current_op = operator.add
for token in parse_result:
if token == '+':
Expand All @@ -203,7 +207,7 @@ def eval_product(parse_result):
[ 1, '*', 2, '/', 3 ] -> 0.66
"""
prod = 1.0
prod = 1
current_op = operator.mul
for token in parse_result:
if token == '*':
Expand Down
4 changes: 2 additions & 2 deletions tests/test_calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,9 @@ def test_other_functions(self):
self.assert_function_values('factorial', fact_inputs, fact_values)

self.assertRaises(ValueError, calc.evaluator, {}, {}, "fact(-1)")
self.assertRaises(ValueError, calc.evaluator, {}, {}, "fact(0.5)")
self.assertRaises((ValueError, TypeError), calc.evaluator, {}, {}, "fact(0.5)")
self.assertRaises(ValueError, calc.evaluator, {}, {}, "factorial(-1)")
self.assertRaises(ValueError, calc.evaluator, {}, {}, "factorial(0.5)")
self.assertRaises((ValueError, TypeError), calc.evaluator, {}, {}, "factorial(0.5)")

def test_constants(self):
"""
Expand Down
4 changes: 3 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
[tox]
envlist = py38,quality
envlist = py{38,311},quality

[testenv]
allowlist_externals =
touch
deps =
setuptools
-r requirements/test.txt
commands =
coverage run setup.py test
coverage report

[testenv:quality]
deps =
setuptools
-r requirements/test.txt
commands =
pycodestyle calc symmath tests
Expand Down

0 comments on commit 19dfd32

Please sign in to comment.