Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
avoid is_GapElement
Browse files Browse the repository at this point in the history
  • Loading branch information
dimpase committed Nov 29, 2022
1 parent d4bde80 commit eb72ef0
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
8 changes: 6 additions & 2 deletions src/sage/rings/finite_rings/element_givaro.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ from cypari2.stack cimport clear_stack

from sage.structure.parent cimport Parent

from sage.interfaces.gap import is_GapElement

try:
from sage.interfaces.gap import GapElement
except ImportError:
GapElement = ()

cdef object is_IntegerMod
cdef object Integer
Expand Down Expand Up @@ -435,7 +439,7 @@ cdef class Cache_givaro(Cache_base):
elif isinstance(e, sage.libs.gap.element.GapElement_FiniteField):
return e.sage(ring=self.parent)

elif is_GapElement(e):
elif isinstance(e, GapElement):
from sage.libs.gap.libgap import libgap
return libgap(e).sage(ring=self.parent)

Expand Down
10 changes: 7 additions & 3 deletions src/sage/rings/finite_rings/element_ntl_gf2e.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,15 @@ from sage.arith.long cimport pyobject_to_long
from .element_pari_ffelt import FiniteFieldElement_pari_ffelt
from .finite_field_ntl_gf2e import FiniteField_ntl_gf2e

from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing

from sage.libs.gap.element import GapElement_FiniteField

from sage.interfaces.gap import is_GapElement
try:
from sage.interfaces.gap import GapElement
except ImportError:
GapElement = ()

from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing

cdef object is_IntegerMod
cdef object IntegerModRing_generic
Expand Down Expand Up @@ -369,7 +373,7 @@ cdef class Cache_ntl_gf2e(Cache_base):
elif isinstance(e, GapElement_FiniteField):
return e.sage(ring=self._parent)

elif is_GapElement(e):
elif isinstance(e, GapElement):
from sage.libs.gap.libgap import libgap
return libgap(e).sage(ring=self._parent)

Expand Down
8 changes: 6 additions & 2 deletions src/sage/rings/finite_rings/element_pari_ffelt.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ from .element_base cimport FinitePolyExtElement
from .integer_mod import IntegerMod_abstract

import sage.rings.integer
from sage.interfaces.gap import is_GapElement
from sage.modules.free_module_element import FreeModuleElement
from sage.rings.integer cimport Integer
from sage.rings.polynomial.polynomial_element import Polynomial
Expand All @@ -39,6 +38,11 @@ from sage.structure.element cimport Element, ModuleElement, RingElement
from sage.structure.richcmp cimport rich_to_bool


try:
from sage.interfaces.gap import GapElement
except ImportError:
GapElement = ()

cdef GEN _INT_to_FFELT(GEN g, GEN x) except NULL:
"""
Convert the t_INT `x` to an element of the field of definition of
Expand Down Expand Up @@ -504,7 +508,7 @@ cdef class FiniteFieldElement_pari_ffelt(FinitePolyExtElement):
elif isinstance(x, str):
self.construct_from(self._parent.polynomial_ring()(x))

elif is_GapElement(x):
elif isinstance(x, GapElement):
try:
from sage.libs.gap.libgap import libgap
self.construct_from(libgap(x).sage(ring=self._parent))
Expand Down
13 changes: 11 additions & 2 deletions src/sage/rings/finite_rings/integer_mod_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@
from sage.structure.factory import UniqueFactory
from sage.structure.richcmp import richcmp, richcmp_method

from sage.interfaces.gap import is_GapElement
try:
from sage.interfaces.gap import GapElement
except ImportError:
GapElement = ()

class IntegerModFactory(UniqueFactory):
r"""
Expand Down Expand Up @@ -1180,13 +1183,19 @@ def _element_constructor_(self, x):
4
sage: libgap(a.sage()) == a
True
better syntax for libgap interface::
sage: a = libgap.Z(13)^2
sage: libgap(a.sage()) == a
True
"""
try:
return integer_mod.IntegerMod(self, x)
except (NotImplementedError, PariError):
raise TypeError("error coercing to finite field")
except TypeError:
if is_GapElement(x):
if isinstance(x, GapElement):
from sage.libs.gap.libgap import libgap
return libgap(x).sage()
raise # Continue up with the original TypeError
Expand Down

0 comments on commit eb72ef0

Please sign in to comment.