From d2c305c05afd1f17e56c6351c39581fdf1295f16 Mon Sep 17 00:00:00 2001 From: rocky Date: Sun, 13 Oct 2024 07:37:12 -0400 Subject: [PATCH] Remove duplication of "intnm" messages --- mathics/builtin/atomic/numbers.py | 12 +++++++++--- mathics/builtin/file_operations/file_utilities.py | 1 - mathics/builtin/files_io/files.py | 5 +---- mathics/builtin/functional/apply_fns_to_lists.py | 5 ++--- mathics/builtin/messages.py | 1 + mathics/builtin/string/charcodes.py | 5 +---- 6 files changed, 14 insertions(+), 15 deletions(-) diff --git a/mathics/builtin/atomic/numbers.py b/mathics/builtin/atomic/numbers.py index a5c92eb3b..df61cdf9e 100644 --- a/mathics/builtin/atomic/numbers.py +++ b/mathics/builtin/atomic/numbers.py @@ -22,7 +22,14 @@ import mpmath import sympy -from mathics.core.atoms import Integer, Integer0, Integer10, MachineReal, Rational +from mathics.core.atoms import ( + Integer, + Integer0, + Integer3, + Integer10, + MachineReal, + Rational, +) from mathics.core.attributes import A_LISTABLE, A_PROTECTED from mathics.core.builtin import Builtin, Predefined from mathics.core.convert.python import from_python @@ -421,7 +428,6 @@ class RealDigits(Builtin): "realx": "The value `1` is not a real number.", "ndig": "The number of digits to return cannot be determined.", "rbase": "Base `1` is not a real number greater than 1.", - "intnm": "Non-negative machine-sized integer expected at position 3 in `1`.", "intm": "Machine-sized integer expected at position 4 in `1`.", } @@ -590,7 +596,7 @@ def eval_with_base_and_length(self, n, b, length, evaluation, pos=None): elements.append(from_python(pos)) expr = Expression(SymbolRealDigits, n, b, length, *elements) if not (isinstance(length, Integer) and length.get_int_value() >= 0): - evaluation.message("RealDigits", "intnm", expr) + evaluation.message("RealDigits", "intnm", Integer3, expr) return return self.eval_with_base( diff --git a/mathics/builtin/file_operations/file_utilities.py b/mathics/builtin/file_operations/file_utilities.py index a341994f0..6f1e063c8 100644 --- a/mathics/builtin/file_operations/file_utilities.py +++ b/mathics/builtin/file_operations/file_utilities.py @@ -37,7 +37,6 @@ class FindList(Builtin): messages = { "strs": "String or non-empty list of strings expected at position `1` in `2`.", - "intnm": "Non-negative machine-sized integer expected at position `1` in `2`.", } options = { diff --git a/mathics/builtin/files_io/files.py b/mathics/builtin/files_io/files.py index 9efb0e43a..dd7df7146 100644 --- a/mathics/builtin/files_io/files.py +++ b/mathics/builtin/files_io/files.py @@ -12,7 +12,7 @@ # We use the below import for access to variables that may change # at runtime. import mathics.eval.files_io.files as io_files -from mathics.core.atoms import Integer, String, SymbolString +from mathics.core.atoms import Integer, Integer3, String, SymbolString from mathics.core.attributes import A_PROTECTED, A_READ_PROTECTED from mathics.core.builtin import ( BinaryOperator, @@ -843,9 +843,6 @@ class Read(Builtin): "readf": "`1` is not a valid format specification.", "readn": "Invalid real number found when reading from `1`.", "readt": "Invalid input found when reading `1` from `2`.", - "intnm": ( - "Non-negative machine-sized integer expected at " "position 3 in `1`." - ), } rules = { diff --git a/mathics/builtin/functional/apply_fns_to_lists.py b/mathics/builtin/functional/apply_fns_to_lists.py index 6f9a70564..57f7b6ab8 100644 --- a/mathics/builtin/functional/apply_fns_to_lists.py +++ b/mathics/builtin/functional/apply_fns_to_lists.py @@ -15,7 +15,7 @@ from typing import Iterable from mathics.builtin.list.constructing import List -from mathics.core.atoms import Integer +from mathics.core.atoms import Integer, Integer3 from mathics.core.builtin import BinaryOperator, Builtin from mathics.core.convert.expression import to_mathics_list from mathics.core.evaluation import Evaluation @@ -328,7 +328,6 @@ class MapThread(Builtin): summary_text = "map a function across corresponding elements in multiple lists" messages = { - "intnm": "Non-negative machine-sized integer expected at position `2` in `1`.", "mptc": "Incompatible dimensions of objects at positions {2, `1`} and {2, `2`} of `3`; dimensions are `4` and `5`.", "mptd": "Object `1` at position {2, `2`} in `3` has only `4` of required `5` dimensions.", "list": "List expected at position `2` in `1`.", @@ -350,7 +349,7 @@ def eval_n(self, f, expr, n, evaluation): n = n.get_int_value() if n is None or n < 0: - evaluation.message("MapThread", "intnm", full_expr, 3) + evaluation.message("MapThread", "intnm", Integer3, full_expr) return if expr.has_form("List", 0): diff --git a/mathics/builtin/messages.py b/mathics/builtin/messages.py index 9241e7159..e524b16e5 100644 --- a/mathics/builtin/messages.py +++ b/mathics/builtin/messages.py @@ -202,6 +202,7 @@ class General(Builtin): "int": "Integer expected.", "intp": "Positive integer expected.", "intnn": "Non-negative integer expected.", + "intnm": "Non-negative machine-sized integer expected at position `1` in `2`.", "iterb": "Iterator does not have appropriate bounds.", "ivar": "`1` is not a valid variable.", "level": ("Level specification `1` is not of the form n, " "{n}, or {m, n}."), diff --git a/mathics/builtin/string/charcodes.py b/mathics/builtin/string/charcodes.py index fe8f99604..67a4e7b71 100644 --- a/mathics/builtin/string/charcodes.py +++ b/mathics/builtin/string/charcodes.py @@ -157,9 +157,6 @@ class FromCharacterCode(Builtin): "A character code, which should be a non-negative integer less " "than 65536, is expected at position `2` in `1`." ), - "intnm": ( - "Non-negative machine-sized integer expected at " "position `2` in `1`." - ), "utf8": "The given codes could not be decoded as utf-8.", } summary_text = "convert from a list of character codes to a string" @@ -212,7 +209,7 @@ def convert_codepoint_list(li): else: pyn = n.get_int_value() if not (isinstance(pyn, int) and pyn > 0 and pyn < sys.maxsize): - evaluation.message("FromCharacterCode", "intnm", exp, Integer1) + evaluation.message("FromCharacterCode", "intnm", Integer1, exp) return return String(convert_codepoint_list([n])) except _InvalidCodepointError: