Skip to content

Commit eec0b62

Browse files
author
Release Manager
committed
gh-35910: fix some pep8 in symbolic folder <!-- Please provide a concise, informative and self-explanatory title. --> <!-- Don't put issue numbers in the title. Put it in the Description below. --> <!-- For example, instead of "Fixes #12345", use "Add a new method to multiply two integers" --> ### 📚 Description fixes some pycodestyle warnings in the symbolic folder. also a few details in the code ; in particular removing a workaround in the subrings of symbolic ring (#19231 ) <!-- Describe your changes here in detail. --> <!-- Why is this change required? What problem does it solve? --> <!-- If this PR resolves an open issue, please link to it here. For example "Fixes #12345". --> <!-- If your change requires a documentation PR, please link it appropriately. --> ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. It should be `[x]` not `[x ]`. --> - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. - [ ] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on - #12345: short description why this is a dependency - #34567: ... --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> URL: #35910 Reported by: Frédéric Chapoton Reviewer(s): Matthias Köppe
2 parents 6a1fdee + d7904e3 commit eec0b62

File tree

9 files changed

+54
-61
lines changed

9 files changed

+54
-61
lines changed

src/sage/symbolic/assumptions.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ def assume(self):
261261
cur = maxima.get("context")
262262
# Redeclaring on the existing context does not seem to trigger
263263
# inconsistency checking.
264-
## maxima.set("context", self._context._maxima_init_())
264+
# maxima.set("context", self._context._maxima_init_())
265265
# Instead, use a temporary context for this purpose
266266
context = maxima.newcontext('context' + maxima._next_var_name())
267267
must_declare = True
@@ -272,7 +272,7 @@ def assume(self):
272272
try:
273273
maxima.eval("declare(%s, %s)" % (self._var._maxima_init_(), self._assumption))
274274
except RuntimeError as mess:
275-
if 'inconsistent' in str(mess): # note Maxima doesn't tell you if declarations are redundant
275+
if 'inconsistent' in str(mess): # note Maxima doesn't tell you if declarations are redundant
276276
# Inconsistency with one of the active contexts.
277277
raise ValueError("Assumption is inconsistent")
278278
else:
@@ -316,9 +316,9 @@ def forget(self):
316316
except KeyError:
317317
return
318318
maxima.deactivate(self._context)
319-
else: # trying to forget a declaration explicitly rather than implicitly
319+
else: # trying to forget a declaration explicitly rather than implicitly
320320
for x in _assumptions:
321-
if repr(self) == repr(x): # so by implication x is also a GenericDeclaration
321+
if repr(self) == repr(x): # so by implication x is also a GenericDeclaration
322322
x.forget()
323323
break
324324
return
@@ -945,8 +945,8 @@ def __init__(self, *args, **kwds):
945945
sage: bool(x>-1)
946946
False
947947
"""
948-
self.replace=kwds.pop("replace",False)
949-
self.Ass=args
948+
self.replace = kwds.pop("replace", False)
949+
self.Ass = args
950950

951951
def __enter__(self):
952952
r"""
@@ -964,7 +964,7 @@ def __enter__(self):
964964
False
965965
"""
966966
if self.replace:
967-
self.OldAss=assumptions()
967+
self.OldAss = assumptions()
968968
forget(assumptions())
969969
assume(self.Ass)
970970

src/sage/symbolic/expression_conversions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ def derivative(self, ex, operator):
582582
raise NotImplementedError
583583
args = ex.operands()
584584
if (not all(isinstance(v, Expression) and v.is_symbol() for v in args) or
585-
len(args) != len(set(args))):
585+
len(args) != len(set(args))):
586586
# An evaluated derivative of the form f'(1) is not a
587587
# symbolic variable, yet we would like to treat it like
588588
# one. So, we replace the argument `1` with a temporary
@@ -1106,7 +1106,7 @@ def derivative(self, ex, operator):
11061106
params_set = set(params)
11071107
mult = ",".join(str(params.count(i)) for i in params_set)
11081108
if (not all(isinstance(v, Expression) and v.is_symbol() for v in args) or
1109-
len(args) != len(set(args))):
1109+
len(args) != len(set(args))):
11101110
# An evaluated derivative of the form f'(1) is not a
11111111
# symbolic variable, yet we would like to treat it like
11121112
# one. So, we replace the argument `1` with a temporary

src/sage/symbolic/integration/external.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ def mma_free_integrator(expression, v, a=None, b=None):
117117
input = "Integrate[{},{}]".format(math_expr, variable)
118118
elif a is not None and b is not None:
119119
input = "Integrate[{},{{{},{},{}}}]".format(math_expr, variable,
120-
a._mathematica_init_(), b._mathematica_init_())
120+
a._mathematica_init_(),
121+
b._mathematica_init_())
121122
else:
122123
raise ValueError('a(={}) and b(={}) should be both None'
123124
' or both defined'.format(a, b))
@@ -252,8 +253,8 @@ def giac_integrator(expression, v, a=None, b=None):
252253
result = ex.integrate(v._giac_(), a._giac_(), b._giac_())
253254
if 'integrate' in format(result) or 'integration' in format(result):
254255
return expression.integrate(v, a, b, hold=True)
255-
else:
256-
return result._sage_()
256+
return result._sage_()
257+
257258

258259
def libgiac_integrator(expression, v, a=None, b=None):
259260
r"""

src/sage/symbolic/maxima_wrapper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# Copyright (C) 2010 Burcin Erocal <[email protected]>
66
# Distributed under the terms of the GNU General Public License (GPL),
77
# version 2 or any later version. The full text of the GPL is available at:
8-
# http://www.gnu.org/licenses/
8+
# https://www.gnu.org/licenses/
99
###############################################################################
1010

1111
from sage.structure.sage_object import SageObject
@@ -158,4 +158,4 @@ def _repr_(self):
158158
sage: u._repr_()
159159
'MaximaWrapper(log(sqrt(2) + 1) + log(sqrt(2) - 1))'
160160
"""
161-
return "MaximaWrapper(%s)"%(self._exp)
161+
return "MaximaWrapper(%s)" % (self._exp)

src/sage/symbolic/pynac_constant.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Wrapper around Pynac's constants
33
"""
44

5-
#*****************************************************************************
5+
# ****************************************************************************
66
# Copyright (C) 2008 William Stein <[email protected]>
77
# Copyright (C) 2008 Burcin Erocal <[email protected]>
88
# Copyright (C) 2009 Mike Hansen <[email protected]>
@@ -11,8 +11,8 @@
1111
# it under the terms of the GNU General Public License as published by
1212
# the Free Software Foundation, either version 2 of the License, or
1313
# (at your option) any later version.
14-
# http://www.gnu.org/licenses/
15-
#*****************************************************************************
14+
# https://www.gnu.org/licenses/
15+
# ****************************************************************************
1616

1717
from sage.misc.lazy_import import lazy_import
1818
lazy_import('sage.symbolic.expression', 'PynacConstant', deprecation=32386)

src/sage/symbolic/relation.py

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ def test_relation_maxima(relation):
502502
except TypeError:
503503
raise ValueError("unable to evaluate the predicate '%s'" % repr(relation))
504504

505-
elif relation.operator() == operator.ne: # operator is not equal
505+
elif relation.operator() == operator.ne: # operator is not equal
506506
try:
507507
s = m.parent()._eval_line('is (notequal(%s,%s))' % (repr(m.lhs()),
508508
repr(m.rhs())))
@@ -518,7 +518,7 @@ def test_relation_maxima(relation):
518518
if s == 'true':
519519
return True
520520
elif s == 'false':
521-
return False # if neither of these, s=='unknown' and we try a few other tricks
521+
return False # if neither of these, s=='unknown' and we try a few other tricks
522522

523523
if relation.operator() != operator.eq:
524524
return False
@@ -1064,7 +1064,7 @@ def solve(f, *args, **kwds):
10641064
"symbolic expression or a list of symbolic "
10651065
"expressions.")
10661066

1067-
if isinstance(f, Expression): # f is a single expression
1067+
if isinstance(f, Expression): # f is a single expression
10681068
return _solve_expression(f, x, explicit_solutions, multiplicities, to_poly_solve, solution_dict, algorithm, domain)
10691069

10701070
if not isinstance(f, (list, tuple)):
@@ -1094,7 +1094,7 @@ def solve(f, *args, **kwds):
10941094
if algorithm == 'sympy':
10951095
from sympy import solve as ssolve
10961096
from sage.interfaces.sympy import sympy_set_to_list
1097-
if isinstance(f, Expression): # f is a single expression
1097+
if isinstance(f, Expression): # f is a single expression
10981098
sympy_f = f._sympy_()
10991099
else:
11001100
sympy_f = [s._sympy_() for s in f]
@@ -1145,27 +1145,27 @@ def solve(f, *args, **kwds):
11451145
else:
11461146
raise
11471147

1148-
if len(s) == 0: # if Maxima's solve gave no solutions, try its to_poly_solve
1148+
if len(s) == 0: # if Maxima's solve gave no solutions, try its to_poly_solve
11491149
try:
11501150
s = m.to_poly_solve(variables)
1151-
except Exception: # if that gives an error, stick with no solutions
1151+
except Exception: # if that gives an error, stick with no solutions
11521152
s = []
11531153

1154-
if len(s) == 0: # if to_poly_solve gave no solutions, try use_grobner
1154+
if len(s) == 0: # if to_poly_solve gave no solutions, try use_grobner
11551155
try:
11561156
s = m.to_poly_solve(variables, 'use_grobner=true')
1157-
except Exception: # if that gives an error, stick with no solutions
1157+
except Exception: # if that gives an error, stick with no solutions
11581158
s = []
11591159

11601160
sol_list = string_to_list_of_solutions(repr(s))
11611161

11621162
# Relaxed form suggested by Mike Hansen (#8553):
11631163
if kwds.get('solution_dict', None):
1164-
if not sol_list: # fixes IndexError on empty solution list (#8553)
1164+
if not sol_list: # fixes IndexError on empty solution list (#8553)
11651165
return []
11661166
if isinstance(sol_list[0], list):
11671167
sol_dict = [{eq.left(): eq.right() for eq in solution}
1168-
for solution in sol_list]
1168+
for solution in sol_list]
11691169
else:
11701170
sol_dict = [{eq.left(): eq.right()} for eq in sol_list]
11711171

@@ -1175,7 +1175,7 @@ def solve(f, *args, **kwds):
11751175

11761176

11771177
def _solve_expression(f, x, explicit_solutions, multiplicities,
1178-
to_poly_solve, solution_dict, algorithm, domain):
1178+
to_poly_solve, solution_dict, algorithm, domain):
11791179
"""
11801180
Solve an expression ``f``. For more information, see :func:`solve`.
11811181
@@ -1305,7 +1305,7 @@ def has_integer_assumption(v):
13051305
alist = assumptions()
13061306
return any(isinstance(a, GenericDeclaration) and a.has(v) and
13071307
a._assumption in ['even', 'odd', 'integer', 'integervalued']
1308-
for a in alist)
1308+
for a in alist)
13091309
if len(ex.variables()) and all(has_integer_assumption(var) for var in ex.variables()):
13101310
return f.solve_diophantine(x, solution_dict=solution_dict)
13111311

@@ -1332,13 +1332,13 @@ def has_integer_assumption(v):
13321332
m = ex._maxima_()
13331333
P = m.parent()
13341334
if explicit_solutions:
1335-
P.eval('solveexplicit: true') # switches Maxima to looking for only explicit solutions
1335+
P.eval('solveexplicit: true') # switches Maxima to looking for only explicit solutions
13361336
try:
13371337
if to_poly_solve != 'force':
13381338
s = m.solve(x).str()
1339-
else: # omit Maxima's solve command
1339+
else: # omit Maxima's solve command
13401340
s = str([])
1341-
except TypeError as mess: # if Maxima's solve has an error, we catch it
1341+
except TypeError as mess: # if Maxima's solve has an error, we catch it
13421342
if "Error executing code in Maxima" in str(mess):
13431343
s = str([])
13441344
else:
@@ -1356,9 +1356,9 @@ def has_integer_assumption(v):
13561356
else:
13571357
return ans
13581358

1359-
X = string_to_list_of_solutions(s) # our initial list of solutions
1359+
X = string_to_list_of_solutions(s) # our initial list of solutions
13601360

1361-
if multiplicities: # to_poly_solve does not return multiplicities, so in this case we end here
1361+
if multiplicities: # to_poly_solve does not return multiplicities, so in this case we end here
13621362
if len(X) == 0:
13631363
return X, []
13641364
else:
@@ -1397,7 +1397,7 @@ def has_integer_assumption(v):
13971397
"unable to make sense of Maxima expression" in \
13981398
str(mess):
13991399
if not explicit_solutions:
1400-
X.append(eq) # we keep this implicit solution
1400+
X.append(eq) # we keep this implicit solution
14011401
else:
14021402
raise
14031403

@@ -1565,8 +1565,6 @@ def solve_mod(eqns, modulus, solution_dict=False):
15651565
[(0,)]
15661566
sage: solve_mod([2*x^2+x*y, -x*y+2*y^2+x-2*y, -2*x^2+2*x*y-y^2-x-y], 1)
15671567
[(0, 0)]
1568-
1569-
15701568
"""
15711569
from sage.rings.finite_rings.integer_mod_ring import Integers
15721570
from sage.rings.integer import Integer
@@ -1585,7 +1583,7 @@ def solve_mod(eqns, modulus, solution_dict=False):
15851583
vars = list(set(sum([list(e.variables()) for e in eqns], [])))
15861584
vars.sort(key=repr)
15871585

1588-
if modulus == 1: # degenerate case
1586+
if modulus == 1: # degenerate case
15891587
ans = [tuple(Integers(1)(0) for v in vars)]
15901588
return ans
15911589

@@ -1611,10 +1609,8 @@ def solve_mod(eqns, modulus, solution_dict=False):
16111609
# if solution_dict == True:
16121610
# Relaxed form suggested by Mike Hansen (#8553):
16131611
if solution_dict:
1614-
sol_dict = [dict(zip(vars, solution)) for solution in ans]
1615-
return sol_dict
1616-
else:
1617-
return ans
1612+
return [dict(zip(vars, solution)) for solution in ans]
1613+
return ans
16181614

16191615

16201616
def _solve_mod_prime_power(eqns, p, m, vars):

src/sage/symbolic/subring.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -403,29 +403,25 @@ def _coerce_map_from_(self, P):
403403
sage: C.has_coerce_map_from(SR) # indirect doctest
404404
False
405405
"""
406-
if P == SR:
407-
# Workaround; can be deleted once #19231 is fixed
408-
return False
409-
410406
from sage.rings.infinity import InfinityRing
411407
from sage.rings.qqbar import AA, QQbar
412408
from sage.rings.real_lazy import RLF, CLF
413409

414410
if isinstance(P, type):
415411
return SR._coerce_map_from_(P)
416412

417-
elif RLF.has_coerce_map_from(P) or \
418-
CLF.has_coerce_map_from(P) or \
419-
AA.has_coerce_map_from(P) or \
420-
QQbar.has_coerce_map_from(P):
413+
if RLF.has_coerce_map_from(P) or \
414+
CLF.has_coerce_map_from(P) or \
415+
AA.has_coerce_map_from(P) or \
416+
QQbar.has_coerce_map_from(P):
421417
return True
422418

423-
elif (P is InfinityRing or
424-
isinstance(P, (sage.rings.abc.RealIntervalField,
425-
sage.rings.abc.ComplexIntervalField))):
419+
if (P is InfinityRing or
420+
isinstance(P, (sage.rings.abc.RealIntervalField,
421+
sage.rings.abc.ComplexIntervalField))):
426422
return True
427423

428-
elif P._is_numerical():
424+
if P._is_numerical():
429425
return P not in (RLF, CLF, AA, QQbar)
430426

431427
def __eq__(self, other):

src/sage/symbolic/substitution_map.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
back to Python.
88
"""
99

10-
#*****************************************************************************
10+
# ****************************************************************************
1111
# Copyright (C) 2013 Volker Braun <[email protected]>
1212
#
1313
# This program is free software: you can redistribute it and/or modify
1414
# it under the terms of the GNU General Public License as published by
1515
# the Free Software Foundation, either version 2 of the License, or
1616
# (at your option) any later version.
17-
# http://www.gnu.org/licenses/
18-
#*****************************************************************************
17+
# https://www.gnu.org/licenses/
18+
# ****************************************************************************
1919

2020
from sage.misc.lazy_import import lazy_import
2121
lazy_import('sage.symbolic.expression', ('SubstitutionMap', 'make_map'), deprecation=32386)

src/sage/symbolic/tests.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
Tests for the Sage/Pynac interaction
33
"""
44

5-
#*****************************************************************************
5+
# ****************************************************************************
66
# Copyright (C) 2013 Volker Braun <[email protected]>
77
#
88
# This program is free software: you can redistribute it and/or modify
99
# it under the terms of the GNU General Public License as published by
1010
# the Free Software Foundation, either version 2 of the License, or
1111
# (at your option) any later version.
12-
# http://www.gnu.org/licenses/
13-
#*****************************************************************************
12+
# https://www.gnu.org/licenses/
13+
# ****************************************************************************
1414

1515

1616
def rational_powers_memleak():
@@ -34,7 +34,7 @@ def rational_powers_memleak():
3434
gc.collect()
3535
c0 = sum(1 for obj in gc.get_objects())
3636
for i in range(1000):
37-
a = ZZ(2).sqrt()
37+
_ = ZZ(2).sqrt()
3838
gc.collect()
3939
c1 = sum(1 for obj in gc.get_objects())
4040
# Test that we do not leak an object at each iteration

0 commit comments

Comments
 (0)