Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mypy errors #1145

Merged
merged 16 commits into from
Oct 26, 2024
7 changes: 4 additions & 3 deletions mathics/builtin/list/constructing.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import typing
from itertools import permutations
from typing import Optional, Tuple
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!


from mathics.builtin.box.layout import RowBox
from mathics.core.atoms import Integer, is_integer_rational_or_real
Expand Down Expand Up @@ -345,12 +346,12 @@ def eval(self, li, evaluation: Evaluation):
def eval_n(self, li, n, evaluation: Evaluation):
"Permutations[li_List, n_]"

rs = None
rs: Optional[Tuple[int, ...]] = None
if isinstance(n, Integer):
py_n = min(n.get_int_value(), len(li.elements))
elif n.has_form("List", 1) and isinstance(n.elements[0], Integer):
py_n = n.elements[0].get_int_value()
rs = [py_n]
rs = (py_n,)
elif (
n.has_form("DirectedInfinity", 1) and n.elements[0].get_int_value() == 1
) or n.get_name() == "System`All":
Expand All @@ -365,7 +366,7 @@ def eval_n(self, li, n, evaluation: Evaluation):
return

if rs is None:
rs = list(range(py_n + 1))
rs = tuple(range(py_n + 1))

inner = structure("List", li, evaluation)
outer = structure("List", inner, evaluation)
Expand Down
6 changes: 3 additions & 3 deletions mathics/builtin/list/rearrange.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,12 +365,12 @@ def _rotate(self, expr, n, evaluation: Evaluation):
return expr

index = (self._sign * n[0]) % len(elements) # with Python's modulo: index >= 1
new_elements = list(chain(elements[index:], elements[:index]))
new_elements = tuple(chain(elements[index:], elements[:index]))

if len(n) > 1:
new_elements = [
new_elements = tuple(
self._rotate(item, n[1:], evaluation) for item in new_elements
]
)

return expr.restructure(expr.head, new_elements, evaluation)

Expand Down
2 changes: 1 addition & 1 deletion mathics/builtin/numbers/calculus.py
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,7 @@ def prepare_sympy(self, elements):
return [elements[0]] + x.elements
return elements

def from_sympy(self, elements: list) -> Expression:
def from_sympy(self, elements: Tuple[BaseElement, ...]) -> Expression:
args = []
for element in elements[1:]:
if element.has_form("List", 1):
Expand Down
2 changes: 1 addition & 1 deletion mathics/core/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ def to_sympy(self, expr, **kwargs):
except TypeError:
pass

def from_sympy(self, elements: list) -> Expression:
def from_sympy(self, elements: Tuple[BaseElement, ...]) -> Expression:
return Expression(Symbol(self.get_name()), *elements)

def prepare_mathics(self, sympy_expr):
Expand Down