Skip to content

Commit 3a2e93b

Browse files
committed
more suggested fixes in giac.pyx
1 parent 7ffe0f8 commit 3a2e93b

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

src/sage/libs/giac/giac.pyx

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,8 @@ from sage.interfaces.giac import giac
170170
171171
172172
# Python3 compatibility ############################
173-
def decstring23(s):
174-
return s.decode()
175-
176-
177173
def encstring23(s):
178174
return bytes(s, 'UTF-8')
179-
180-
181-
listrange = list, range
182175
# End of Python3 compatibility #####################
183176
184177
@@ -848,7 +841,7 @@ cdef class Pygen(GiacMethods_base):
848841
self.gptr = new gen((<Pygen>s).gptr[0])
849842
sig_off()
850843
851-
elif isinstance(s, listrange):
844+
elif isinstance(s, (list, range)):
852845
sig_on()
853846
self.gptr = new gen(_wrap_pylist(<list>s),<short int>0)
854847
sig_off()
@@ -866,7 +859,7 @@ cdef class Pygen(GiacMethods_base):
866859
s = s._giac_init_()
867860
except AttributeError:
868861
s = SRexpressiontoGiac(s)
869-
if not(isinstance(s, str)): #modif python3
862+
if not isinstance(s, str):
870863
s = s.__str__()
871864
sig_on()
872865
self.gptr = new gen(<string>encstring23(s),context_ptr)
@@ -882,7 +875,7 @@ cdef class Pygen(GiacMethods_base):
882875
sig_off()
883876
if t < 6000:
884877
sig_on()
885-
result = decstring23(GIAC_print(self.gptr[0], context_ptr).c_str()) #python3
878+
result = GIAC_print(self.gptr[0], context_ptr).c_str().decode()
886879
sig_off()
887880
return result
888881
else:
@@ -895,7 +888,7 @@ cdef class Pygen(GiacMethods_base):
895888
#if self.gptr == NULL:
896889
# return ''
897890
sig_on()
898-
result = decstring23(GIAC_print(self.gptr[0], context_ptr).c_str())
891+
result = GIAC_print(self.gptr[0], context_ptr).c_str().decode()
899892
sig_off()
900893
return result
901894
@@ -926,7 +919,7 @@ cdef class Pygen(GiacMethods_base):
926919
TESTS::
927920
928921
sage: from sage.libs.giac.giac import libgiac
929-
sage: l=libgiac(list(range(10^6)));l[5] #python3
922+
sage: l=libgiac(list(range(10^6)));l[5]
930923
5
931924
sage: l[35:50:7]
932925
[35,42,49]
@@ -1156,7 +1149,7 @@ cdef class Pygen(GiacMethods_base):
11561149
sig_off()
11571150
return _wrap_gen(result)
11581151
1159-
#PB / in python3 is truediv
1152+
# PB / in python3 is truediv
11601153
def __div__(self, right):
11611154
"""
11621155
TESTS::
@@ -1296,8 +1289,8 @@ cdef class Pygen(GiacMethods_base):
12961289
# if (not lang in ['en', 'fr', 'el']):
12971290
# lang='en'
12981291
# try:
1299-
# url=decstring23(browser_help(self.gptr[0],l[lang])) #python3
1300-
# giacbasedir=decstring23(GIAC_giac_aide_dir()) # python3
1292+
# url=browser_help(self.gptr[0],l[lang]).decode()
1293+
# giacbasedir=GIAC_giac_aide_dir().decode()
13011294
# except:
13021295
# raise RuntimeError('giac docs dir not found')
13031296
# print(url)
@@ -1338,7 +1331,7 @@ cdef class Pygen(GiacMethods_base):
13381331
\frac{...x^{4}...-...y...}{...y^{2}-3...x...}
13391332
"""
13401333
sig_on()
1341-
result = decstring23(GIAC_gen2tex(self.gptr[0], context_ptr).c_str())
1334+
result = GIAC_gen2tex(self.gptr[0], context_ptr).c_str().decode()
13421335
sig_off()
13431336
return result
13441337
@@ -1787,7 +1780,7 @@ cdef vecteur _wrap_pylist(L) except +:
17871780
cdef vecteur * V
17881781
cdef int i
17891782
1790-
if (isinstance(L, tuple) or isinstance(L, listrange)):
1783+
if isinstance(L, (tuple, list, range):
17911784
n=len(L)
17921785
V=new vecteur()
17931786
@@ -1807,14 +1800,14 @@ cdef vecteur _getgiacslice(Pygen L,slice sl) except +:
18071800
cdef vecteur * V
18081801
cdef int u
18091802
1810-
if (L.type()=="DOM_LIST"):
1803+
if L.type()=="DOM_LIST":
18111804
n=len(L)
18121805
V=new vecteur()
18131806
18141807
sig_on()
18151808
# for u in range(n)[sl]: #pb python3
1816-
(b,e,st)=sl.indices(n)
1817-
for u in range(b,e,st):
1809+
b, e, st = sl.indices(n)
1810+
for u in range(b, e, st):
18181811
V.push_back((L.gptr[0])[u])
18191812
sig_off()
18201813
return V[0]

0 commit comments

Comments
 (0)