Skip to content

Magma interface poorly supports strings #37978

@edgarcosta

Description

@edgarcosta

Steps To Reproduce

sage: foo = "string"
sage: magma(foo)
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
File /home/sage/sage-10.2/src/sage/interfaces/expect.py:1496, in ExpectElement.__init__(self, parent, value, is_name, name)
   1495 try:
-> 1496     self._name = parent._create(value, name=name)
   1497 # Convert ValueError and RuntimeError to TypeError for
   1498 # coercion to work properly.

File /home/sage/sage-10.2/src/sage/interfaces/interface.py:516, in Interface._create(self, value, name)
    515 name = self._next_var_name() if name is None else name
--> 516 self.set(name, value)
    517 return name

File /home/sage/sage-10.2/src/sage/interfaces/magma.py:626, in Magma.set(self, var, value)
    609 """
    610 Set the variable var to the given value in the Magma interpreter.
    611
   (...)
    624     13/5
    625 """
--> 626 out = self.eval("%s:=%s" % (var, value))
    627 if out.lower().find("error") != -1:

File /home/sage/sage-10.2/src/sage/interfaces/magma.py:559, in Magma.eval(self, x, strip, **kwds)
    558 if 'Runtime error' in ans or 'User error' in ans:
--> 559     raise RuntimeError("Error evaluating Magma code.\nIN:%s\nOUT:%s" % (x, ans))
    560 return ans

RuntimeError: Error evaluating Magma code.
IN:_sage_[1]:=string;
OUT:
>> _sage_[1]:=string;
              ^
User error: Identifier 'string' has not been declared or assigned

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
Cell In [2], line 1
----> 1 magma(foo)

File /home/sage/sage-10.2/src/sage/interfaces/magma.py:791, in Magma.__call__(self, x, gens)
    788 except TypeError:  # if x isn't hashable
    789     pass
--> 791 A = Expect.__call__(self, x)
    792 if has_cache:
    793     x._magma_cache[self] = A

File /home/sage/sage-10.2/src/sage/interfaces/interface.py:298, in Interface.__call__(self, x, name)
    295         pass
    297 if isinstance(x, str):
--> 298     return cls(self, x, name=name)
    299 try:
    300     # Special methods do not and should not have an option to
    301     # set the name directly, as the identifier assigned by the
    302     # interface should stay consistent. An identifier with a
    303     # user-assigned name might change its value, so we return a
    304     # new element.
    305     result = self._coerce_from_special_method(x)

File /home/sage/sage-10.2/src/sage/interfaces/expect.py:1501, in ExpectElement.__init__(self, parent, value, is_name, name)
   1499 except (RuntimeError, ValueError) as x:
   1500     self._session_number = -1
-> 1501     raise TypeError(*x.args)
   1502 except BaseException:
   1503     self._session_number = -1

TypeError: Error evaluating Magma code.
IN:_sage_[1]:=string;
OUT:
>> _sage_[1]:=string;
              ^
User error: Identifier 'string' has not been declared or assigned

Checklist

  • I have searched the existing issues for a bug report that matches the one I want to file, without success.
  • I have read the documentation and troubleshoot guide

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions