From 857b313199c2fca00e30e2641d2af928e91293bd Mon Sep 17 00:00:00 2001 From: Chintan Joshi Date: Thu, 28 Mar 2024 14:43:54 +0300 Subject: [PATCH 1/6] build: python 3.11 support --- .github/workflows/ci.yml | 4 ++-- requirements/base.txt | 2 +- requirements/ci.txt | 11 +++-------- requirements/pip.txt | 2 +- requirements/pip_tools.txt | 13 +------------ requirements/test.txt | 15 +++------------ requirements/tox.txt | 10 +++------- setup.py | 1 + tox.ini | 2 +- 9 files changed, 16 insertions(+), 44 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 09361f4..29ab8c8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,8 +15,8 @@ jobs: strategy: matrix: os: [ ubuntu-20.04 ] - python-version: [ 3.8 ] - toxenv: [ py38, quality ] + python-version: [ 3.8, 3.11 ] + toxenv: [ py38, py311, quality ] steps: - uses: actions/checkout@v2 diff --git a/requirements/base.txt b/requirements/base.txt index e42ef85..917b439 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -1,5 +1,5 @@ # -# This file is autogenerated by pip-compile with Python 3.8 +# This file is autogenerated by pip-compile with Python 3.11 # by the following command: # # make upgrade diff --git a/requirements/ci.txt b/requirements/ci.txt index c45838a..b5bda80 100644 --- a/requirements/ci.txt +++ b/requirements/ci.txt @@ -1,5 +1,5 @@ # -# This file is autogenerated by pip-compile with Python 3.8 +# This file is autogenerated by pip-compile with Python 3.11 # by the following command: # # make upgrade @@ -30,7 +30,7 @@ distlib==0.3.8 # virtualenv docopt==0.6.2 # via coveralls -filelock==3.13.1 +filelock==3.13.3 # via # -r requirements/tox.txt # tox @@ -57,12 +57,7 @@ pyproject-api==1.6.1 # tox requests==2.31.0 # via coveralls -tomli==2.0.1 - # via - # -r requirements/tox.txt - # pyproject-api - # tox -tox==4.14.1 +tox==4.14.2 # via -r requirements/tox.txt urllib3==2.2.1 # via requests diff --git a/requirements/pip.txt b/requirements/pip.txt index cf44902..218ba66 100644 --- a/requirements/pip.txt +++ b/requirements/pip.txt @@ -1,5 +1,5 @@ # -# This file is autogenerated by pip-compile with Python 3.8 +# This file is autogenerated by pip-compile with Python 3.11 # by the following command: # # make upgrade diff --git a/requirements/pip_tools.txt b/requirements/pip_tools.txt index 152da44..14de3e4 100644 --- a/requirements/pip_tools.txt +++ b/requirements/pip_tools.txt @@ -1,5 +1,5 @@ # -# This file is autogenerated by pip-compile with Python 3.8 +# This file is autogenerated by pip-compile with Python 3.11 # by the following command: # # make upgrade @@ -8,10 +8,6 @@ build==1.1.1 # via pip-tools click==8.1.7 # via pip-tools -importlib-metadata==6.11.0 - # via - # -c https://raw.githubusercontent.com/edx/edx-lint/master/edx_lint/files/common_constraints.txt - # build packaging==24.0 # via build pip-tools==7.4.1 @@ -20,15 +16,8 @@ pyproject-hooks==1.0.0 # via # build # pip-tools -tomli==2.0.1 - # via - # build - # pip-tools - # pyproject-hooks wheel==0.43.0 # via pip-tools -zipp==3.18.1 - # via importlib-metadata # The following packages are considered to be unsafe in a requirements file: # pip diff --git a/requirements/test.txt b/requirements/test.txt index f9dda99..2d79127 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -1,5 +1,5 @@ # -# This file is autogenerated by pip-compile with Python 3.8 +# This file is autogenerated by pip-compile with Python 3.11 # by the following command: # # make upgrade @@ -31,7 +31,7 @@ distlib==0.3.8 # via virtualenv edx-lint==5.3.6 # via -r requirements/test.in -filelock==3.13.1 +filelock==3.13.3 # via # tox # virtualenv @@ -103,18 +103,9 @@ sympy==1.12 # via -r requirements/base.txt text-unidecode==1.3 # via python-slugify -tomli==2.0.1 - # via - # pylint - # pyproject-api - # tox tomlkit==0.12.4 # via pylint -tox==4.14.1 +tox==4.14.2 # via -r requirements/test.in -typing-extensions==4.10.0 - # via - # astroid - # pylint virtualenv==20.25.1 # via tox diff --git a/requirements/tox.txt b/requirements/tox.txt index daf54ce..a48174f 100644 --- a/requirements/tox.txt +++ b/requirements/tox.txt @@ -1,5 +1,5 @@ # -# This file is autogenerated by pip-compile with Python 3.8 +# This file is autogenerated by pip-compile with Python 3.11 # by the following command: # # make upgrade @@ -12,7 +12,7 @@ colorama==0.4.6 # via tox distlib==0.3.8 # via virtualenv -filelock==3.13.1 +filelock==3.13.3 # via # tox # virtualenv @@ -28,11 +28,7 @@ pluggy==1.4.0 # via tox pyproject-api==1.6.1 # via tox -tomli==2.0.1 - # via - # pyproject-api - # tox -tox==4.14.1 +tox==4.14.2 # via -r requirements/tox.in virtualenv==20.25.1 # via tox diff --git a/setup.py b/setup.py index c6e7030..0ba094d 100644 --- a/setup.py +++ b/setup.py @@ -78,5 +78,6 @@ def get_version(*file_paths): 'Natural Language :: English', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.11', ], ) diff --git a/tox.ini b/tox.ini index 4e25818..88b4afa 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py38,quality +envlist = py{38, 311}quality [testenv] allowlist_externals = From a37dafcb3b3668d5e636793df3d21f2c42d21a5d Mon Sep 17 00:00:00 2001 From: Chintan Joshi Date: Thu, 28 Mar 2024 14:44:43 +0300 Subject: [PATCH 2/6] build: conditional change for python 3.11 support --- calc/calc.py | 5 +++++ tests/test_calc.py | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/calc/calc.py b/calc/calc.py index bee9310..907d095 100644 --- a/calc/calc.py +++ b/calc/calc.py @@ -265,6 +265,11 @@ def eval_variable(x): return all_variables[casify(x[0])] def eval_function(x): + # This condition here is only for factorial function + if isinstance(x[1], numbers.Real): + if math.ceil(x[1]) == x[1]: + return all_functions[casify(x[0])](int(x[1])) + return all_functions[casify(x[0])](x[1]) evaluate_actions = { diff --git a/tests/test_calc.py b/tests/test_calc.py index bb980b4..47f3202 100644 --- a/tests/test_calc.py +++ b/tests/test_calc.py @@ -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(TypeError, calc.evaluator, {}, {}, "fact(0.5)") self.assertRaises(ValueError, calc.evaluator, {}, {}, "factorial(-1)") - self.assertRaises(ValueError, calc.evaluator, {}, {}, "factorial(0.5)") + self.assertRaises(TypeError, calc.evaluator, {}, {}, "factorial(0.5)") def test_constants(self): """ From 9fdb05ecad38cfc65f53125890c1ff804d1578d9 Mon Sep 17 00:00:00 2001 From: Chintan Joshi Date: Thu, 28 Mar 2024 16:05:03 +0300 Subject: [PATCH 3/6] fix: testcase error type --- .github/workflows/ci.yml | 2 +- tests/test_calc.py | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 29ab8c8..f323f9b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,7 @@ jobs: matrix: os: [ ubuntu-20.04 ] python-version: [ 3.8, 3.11 ] - toxenv: [ py38, py311, quality ] + toxenv: [ py38, quality ] steps: - uses: actions/checkout@v2 diff --git a/tests/test_calc.py b/tests/test_calc.py index 47f3202..b43d423 100644 --- a/tests/test_calc.py +++ b/tests/test_calc.py @@ -348,9 +348,13 @@ def test_other_functions(self): self.assert_function_values('factorial', fact_inputs, fact_values) self.assertRaises(ValueError, calc.evaluator, {}, {}, "fact(-1)") - self.assertRaises(TypeError, calc.evaluator, {}, {}, "fact(0.5)") + # There are 2 errors below because py3.8 raises ValueError and 3.11 raises TypeError + # Value error to be removed when we remove py3.8 support + self.assertRaises((TypeError, ValueError), calc.evaluator, {}, {}, "fact(0.5)") self.assertRaises(ValueError, calc.evaluator, {}, {}, "factorial(-1)") - self.assertRaises(TypeError, calc.evaluator, {}, {}, "factorial(0.5)") + # There are 2 errors below because py3.8 raises ValueError and 3.11 raises TypeError + # Value error to be removed when we remove py3.8 support + self.assertRaises((TypeError, ValueError), calc.evaluator, {}, {}, "factorial(0.5)") def test_constants(self): """ From 6da1d9329202c1aa95a39b13f36b38a0c9b9f0f5 Mon Sep 17 00:00:00 2001 From: Chintan Joshi Date: Wed, 3 Apr 2024 19:46:19 +0300 Subject: [PATCH 4/6] build: with python 3.8 instead of 3.11 --- requirements/base.txt | 4 ++-- requirements/ci.txt | 7 ++++++- requirements/pip.txt | 2 +- requirements/pip_tools.txt | 15 +++++++++++++-- requirements/test.txt | 13 +++++++++++-- requirements/tox.txt | 6 +++++- 6 files changed, 38 insertions(+), 9 deletions(-) diff --git a/requirements/base.txt b/requirements/base.txt index 917b439..c3accbc 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -1,10 +1,10 @@ # -# This file is autogenerated by pip-compile with Python 3.11 +# This file is autogenerated by pip-compile with Python 3.8 # by the following command: # # make upgrade # -lxml==5.1.0 +lxml==5.2.1 # via -r requirements/base.in markupsafe==2.1.5 # via -r requirements/base.in diff --git a/requirements/ci.txt b/requirements/ci.txt index b5bda80..53fbcda 100644 --- a/requirements/ci.txt +++ b/requirements/ci.txt @@ -1,5 +1,5 @@ # -# This file is autogenerated by pip-compile with Python 3.11 +# This file is autogenerated by pip-compile with Python 3.8 # by the following command: # # make upgrade @@ -57,6 +57,11 @@ pyproject-api==1.6.1 # tox requests==2.31.0 # via coveralls +tomli==2.0.1 + # via + # -r requirements/tox.txt + # pyproject-api + # tox tox==4.14.2 # via -r requirements/tox.txt urllib3==2.2.1 diff --git a/requirements/pip.txt b/requirements/pip.txt index 218ba66..cf44902 100644 --- a/requirements/pip.txt +++ b/requirements/pip.txt @@ -1,5 +1,5 @@ # -# This file is autogenerated by pip-compile with Python 3.11 +# This file is autogenerated by pip-compile with Python 3.8 # by the following command: # # make upgrade diff --git a/requirements/pip_tools.txt b/requirements/pip_tools.txt index 14de3e4..e64299a 100644 --- a/requirements/pip_tools.txt +++ b/requirements/pip_tools.txt @@ -1,13 +1,17 @@ # -# This file is autogenerated by pip-compile with Python 3.11 +# This file is autogenerated by pip-compile with Python 3.8 # by the following command: # # make upgrade # -build==1.1.1 +build==1.2.1 # via pip-tools click==8.1.7 # via pip-tools +importlib-metadata==6.11.0 + # via + # -c https://raw.githubusercontent.com/edx/edx-lint/master/edx_lint/files/common_constraints.txt + # build packaging==24.0 # via build pip-tools==7.4.1 @@ -16,8 +20,15 @@ pyproject-hooks==1.0.0 # via # build # pip-tools +tomli==2.0.1 + # via + # build + # pip-tools + # pyproject-hooks wheel==0.43.0 # via pip-tools +zipp==3.18.1 + # via importlib-metadata # The following packages are considered to be unsafe in a requirements file: # pip diff --git a/requirements/test.txt b/requirements/test.txt index 2d79127..597918f 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -1,5 +1,5 @@ # -# This file is autogenerated by pip-compile with Python 3.11 +# This file is autogenerated by pip-compile with Python 3.8 # by the following command: # # make upgrade @@ -39,7 +39,7 @@ isort==5.13.2 # via pylint jinja2==3.1.3 # via code-annotations -lxml==5.1.0 +lxml==5.2.1 # via -r requirements/base.txt markupsafe==2.1.5 # via @@ -103,9 +103,18 @@ sympy==1.12 # via -r requirements/base.txt text-unidecode==1.3 # via python-slugify +tomli==2.0.1 + # via + # pylint + # pyproject-api + # tox tomlkit==0.12.4 # via pylint tox==4.14.2 # via -r requirements/test.in +typing-extensions==4.10.0 + # via + # astroid + # pylint virtualenv==20.25.1 # via tox diff --git a/requirements/tox.txt b/requirements/tox.txt index a48174f..cc5293d 100644 --- a/requirements/tox.txt +++ b/requirements/tox.txt @@ -1,5 +1,5 @@ # -# This file is autogenerated by pip-compile with Python 3.11 +# This file is autogenerated by pip-compile with Python 3.8 # by the following command: # # make upgrade @@ -28,6 +28,10 @@ pluggy==1.4.0 # via tox pyproject-api==1.6.1 # via tox +tomli==2.0.1 + # via + # pyproject-api + # tox tox==4.14.2 # via -r requirements/tox.in virtualenv==20.25.1 From 4c5a13e377599ae2d3e2784b30e8ba07df6baf6d Mon Sep 17 00:00:00 2001 From: Feanil Patel Date: Wed, 3 Apr 2024 12:26:15 -0400 Subject: [PATCH 5/6] feat: Add python 3.11 support. Update evaluation functions to not coerce integers to floating point numbers when not necessary. --- calc/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/calc/__init__.py b/calc/__init__.py index 434fcd9..1a9b5fa 100644 --- a/calc/__init__.py +++ b/calc/__init__.py @@ -6,4 +6,4 @@ from .calc import * -__version__ = '3.0.1' +__version__ = '3.1.0' From 3347c022977349afa3434c8d3abf66e8329a0ce7 Mon Sep 17 00:00:00 2001 From: Chintan Joshi Date: Mon, 8 Apr 2024 18:50:13 +0300 Subject: [PATCH 6/6] build: python 3.11 support --- calc/calc.py | 15 +++++++-------- tox.ini | 4 +++- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/calc/calc.py b/calc/calc.py index 907d095..1fea477 100644 --- a/calc/calc.py +++ b/calc/calc.py @@ -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): @@ -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 == '+': @@ -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 == '*': @@ -265,11 +269,6 @@ def eval_variable(x): return all_variables[casify(x[0])] def eval_function(x): - # This condition here is only for factorial function - if isinstance(x[1], numbers.Real): - if math.ceil(x[1]) == x[1]: - return all_functions[casify(x[0])](int(x[1])) - return all_functions[casify(x[0])](x[1]) evaluate_actions = { diff --git a/tox.ini b/tox.ini index 88b4afa..3d77849 100644 --- a/tox.ini +++ b/tox.ini @@ -1,10 +1,11 @@ [tox] -envlist = py{38, 311}quality +envlist = py{38,311},quality [testenv] allowlist_externals = touch deps = + setuptools -r requirements/test.txt commands = coverage run setup.py test @@ -12,6 +13,7 @@ commands = [testenv:quality] deps = + setuptools -r requirements/test.txt commands = pycodestyle calc symmath tests