Skip to content

Commit d5a1370

Browse files
author
Release Manager
committed
gh-39905: Improve documentation of various gap-related methods As in the title. There will be no visible change to the user because these methods all start with `_`, only to Sage developers. The reason is… there's a lot of confusion in downstream implementations, so it looks like whoever initially wrote that code wasn't aware of the convention. See #39908 . ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [ ] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [x] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - #12345: short description why this is a dependency --> <!-- - #34567: ... --> URL: #39905 Reported by: user202729 Reviewer(s): Frédéric Chapoton, user202729
2 parents 1b43bdb + 4b238ad commit d5a1370

File tree

3 files changed

+71
-1
lines changed

3 files changed

+71
-1
lines changed

src/sage/libs/gap/util.pxd

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,4 @@ cdef initialize()
4242
### Evaluate string in GAP #################################################
4343
############################################################################
4444

45-
# Evaluate a string
4645
cdef Obj gap_eval(str gap_string) except? NULL

src/sage/libs/gap/util.pyx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,10 @@ cdef Obj gap_eval(str gap_string) except? NULL:
338338
r"""
339339
Evaluate a string in GAP.
340340
341+
This function cannot be used directly from Python, use
342+
:meth:`~sage.libs.gap.libgap.Gap.eval` method on global ``libgap``
343+
variable instead.
344+
341345
INPUT:
342346
343347
- ``gap_string`` -- string; a valid statement in GAP

src/sage/structure/sage_object.pyx

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,17 +741,84 @@ cdef class SageObject:
741741
return True
742742

743743
def _gap_(self, G=None):
744+
"""
745+
Return a Gap object.
746+
747+
Unlike :meth:`_libgap_`, this method returns an instance of
748+
:class:`sage.interfaces.gap.GapElement`, which wraps an object
749+
in the GAP interpreter spawned as a subprocess of Sage.
750+
751+
Typically you should not need to call this method directly,
752+
instead just call :mod:`~sage.interfaces.gap`
753+
on the object. See example below.
754+
755+
EXAMPLES::
756+
757+
sage: a = gap(2/3); a
758+
2/3
759+
sage: type(a)
760+
<class 'sage.interfaces.gap.GapElement'>
761+
762+
sage: a = (2/3)._gap_(); a
763+
2/3
764+
sage: type(a)
765+
<class 'sage.interfaces.gap.GapElement'>
766+
"""
744767
if G is None:
745768
import sage.interfaces.gap
746769
G = sage.interfaces.gap.gap
747770
return self._interface_(G)
748771

749772
def _gap_init_(self):
773+
"""
774+
Return a string that provides a representation of ``self`` in GAP.
775+
776+
This method is indirectly used by :meth:`_libgap_` and :meth:`_gap_`
777+
by essentially passing their output to
778+
:meth:`libgap.eval <sage.libs.gap.libgap.Gap.eval>`
779+
and :mod:`~sage.interfaces.gap` respectively,
780+
unless the subclass overrides them with more efficient variants.
781+
782+
EXAMPLES::
783+
784+
sage: (2/3)._gap_init_()
785+
'2/3'
786+
sage: Zmod(4)._gap_init_()
787+
'ZmodnZ(4)'
788+
"""
750789
import sage.interfaces.gap
751790
I = sage.interfaces.gap.gap
752791
return self._interface_init_(I)
753792

754793
def _libgap_(self):
794+
"""
795+
Return a libgap object.
796+
797+
Unlike :meth:`_gap_`, this method returns an instance of
798+
:class:`sage.libs.gap.libgap.GapElement`, which wraps an object
799+
in libgap embedded in Sage. As explained in
800+
:mod:`sage.libs.gap.libgap`, this is much faster.
801+
802+
Typically you should not need to call this method directly,
803+
instead use :mod:`~sage.libs.gap.libgap`. See example below.
804+
805+
By default, this method makes use of :meth:`_gap_init_`.
806+
Subclasses could override this method to provide a more efficient
807+
implementation.
808+
809+
EXAMPLES::
810+
811+
sage: a = libgap(2/3); a
812+
2/3
813+
sage: type(a)
814+
<class 'sage.libs.gap.element.GapElement_Rational'>
815+
816+
TESTS::
817+
818+
sage: from sage.libs.gap.element import GapElement
819+
sage: isinstance(a, GapElement)
820+
True
821+
"""
755822
from sage.libs.gap.libgap import libgap
756823
return libgap.eval(self)
757824

0 commit comments

Comments
 (0)