Skip to content

Commit

Permalink
Explicit Union
Browse files Browse the repository at this point in the history
  • Loading branch information
davidar committed Oct 26, 2024
1 parent e2826a6 commit cf2a666
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions mathics/builtin/box/expression.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions mathics/core/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions mathics/core/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion mathics/core/pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion mathics/core/symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mathics/eval/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit cf2a666

Please sign in to comment.