From da8580c81e671f0a26fbafd4b0c5572cfa05592b Mon Sep 17 00:00:00 2001 From: rocky Date: Sun, 20 Nov 2022 10:51:56 -0500 Subject: [PATCH] Add annotiations to some globals ... and add run pytest setting MATHICS_CHARACTER_ENCODING --- Makefile | 2 +- mathics/builtin/__init__.py | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index bef14777a..9b2e85a0b 100644 --- a/Makefile +++ b/Makefile @@ -112,7 +112,7 @@ clean: clean-cython clean-cache #: Run py.test tests. Use environment variable "o" for pytest options pytest: - $(PYTHON) -m pytest $(PYTEST_WORKERS) test $o + MATHICS_CHARACTER_ENCODING="ASCII" $(PYTHON) -m pytest $(PYTEST_WORKERS) test $o #: Run a more extensive pattern-matching test diff --git a/mathics/builtin/__init__.py b/mathics/builtin/__init__.py index 5500cf970..b8ba51021 100755 --- a/mathics/builtin/__init__.py +++ b/mathics/builtin/__init__.py @@ -11,7 +11,7 @@ import os.path as osp import pkgutil import re -from typing import List, Optional +from typing import Dict, List, Optional, Type from mathics.builtin.base import ( Builtin, @@ -31,11 +31,18 @@ for f in glob.glob(osp.join(osp.dirname(__file__), "[a-z]*.py")) ] -system_builtins_dict = {} -builtins_by_module = {} +# system_builtins_dict maps a full builtin name, e.g. "System`EulerPhi" to a Builtin class +system_builtins_dict: Dict[str, Type[Builtin]] = {} +# builtins_by_module maps a full module name, e.g. "mathics.builtin.evaluation" to a +# list of Builtin classes. +builtins_by_module: Dict[str, List[Type[Builtin]]] = {} -def add_builtins(new_builtins): + +def add_builtins(new_builtins: list): + """ + Updates system_builtins_dict to insert new_builtins. + """ for var_name, builtin in new_builtins: name = builtin.get_name() if hasattr(builtin, "python_equivalent"): @@ -233,7 +240,7 @@ def sanity_check(cls, module): _builtins_list.append((instance.get_name(), instance)) builtins_by_module[module.__name__].append(instance) -mathics_to_sympy = {} # here we have: name -> sympy object +mathics_to_sympy: Dict[str, Type[Builtin]] = {} # here we have: name -> sympy object sympy_to_mathics = {} builtins_precedence = {}