diff --git a/mathics/builtin/box/expression.py b/mathics/builtin/box/expression.py index b606ce5f4..a6243314f 100644 --- a/mathics/builtin/box/expression.py +++ b/mathics/builtin/box/expression.py @@ -1,7 +1,7 @@ # This is never intended to go in Mathics3 docs no_doc = True -from typing import Optional, Sequence +from typing import Optional, Sequence, Union from mathics.core.attributes import A_PROTECTED, A_READ_PROTECTED from mathics.core.builtin import BuiltinElement @@ -126,7 +126,7 @@ def head(self, value): raise ValueError("BoxExpression.head is write protected.") def has_form( - self, heads: Sequence[str] | str, *element_counts: Optional[int] + self, heads: Union[Sequence[str], str], *element_counts: Optional[int] ) -> bool: """ element_counts: diff --git a/mathics/core/element.py b/mathics/core/element.py index c2a30c8cb..6c77e7829 100644 --- a/mathics/core/element.py +++ b/mathics/core/element.py @@ -6,7 +6,7 @@ """ from abc import ABC -from typing import Any, Optional, Sequence, Tuple +from typing import Any, Optional, Sequence, Tuple, Union from mathics.core.attributes import A_NO_ATTRIBUTES @@ -388,7 +388,7 @@ def is_numeric(self, evaluation=None) -> bool: return False def has_form( - self, heads: Sequence[str] | str, *element_counts: Optional[int] + self, heads: Union[Sequence[str], str], *element_counts: Optional[int] ) -> bool: """Check if the expression is of the form Head[l1,...,ln] with Head.name in `heads` and a number of elements according to the specification in diff --git a/mathics/core/expression.py b/mathics/core/expression.py index 363ac8366..987176b73 100644 --- a/mathics/core/expression.py +++ b/mathics/core/expression.py @@ -784,7 +784,7 @@ def get_option_values( values = self.flatten_with_respect_to_head(SymbolList).elements else: values = [self] - option_values: dict[str, str | BaseElement] = {} + option_values: dict[str, Union[str, BaseElement]] = {} for option in values: symbol_name = option.get_name() if allow_symbols and symbol_name: @@ -1035,7 +1035,7 @@ def is_uncertain_final_definitions(self, definitions) -> bool: return definitions.is_uncertain_final_value(time, cache.symbols) def has_form( - self, heads: Sequence[str] | str, *element_counts: Optional[int] + self, heads: Union[Sequence[str], str], *element_counts: Optional[int] ) -> bool: """ element_counts: diff --git a/mathics/core/pattern.py b/mathics/core/pattern.py index e6433ca73..dc5d247bb 100644 --- a/mathics/core/pattern.py +++ b/mathics/core/pattern.py @@ -236,7 +236,7 @@ def get_option_values( return self.expr.get_option_values(evaluation, allow_symbols, stop_on_error) def has_form( - self, heads: Sequence[str] | str, *element_counts: Optional[int] + self, heads: Union[Sequence[str], str], *element_counts: Optional[int] ) -> bool: """Compare the expression against a form""" return self.expr.has_form(heads, *element_counts) diff --git a/mathics/core/symbols.py b/mathics/core/symbols.py index 60d170d7b..0206ad182 100644 --- a/mathics/core/symbols.py +++ b/mathics/core/symbols.py @@ -290,7 +290,7 @@ def get_sort_key(self, pattern_sort=False) -> tuple: raise NotImplementedError def has_form( - self, heads: Sequence[str] | str, *element_counts: Optional[int] + self, heads: Union[Sequence[str], str], *element_counts: Optional[int] ) -> bool: if element_counts: return False diff --git a/mathics/eval/rules.py b/mathics/eval/rules.py index fbbeb9d21..a6892d10f 100644 --- a/mathics/eval/rules.py +++ b/mathics/eval/rules.py @@ -18,7 +18,7 @@ def create_rules( name: str, evaluation: Evaluation, extra_args: OptionalType[List] = None, -) -> Tuple[Union[List[Rule], BaseElement, None], bool] | "Dispatch": +) -> Union[Tuple[Union[List[Rule], BaseElement, None], bool], "Dispatch"]: """ This function implements `Replace`, `ReplaceAll`, `ReplaceRepeated` and `ReplaceList` eval methods.