Skip to content

Commit f418290

Browse files
committed
some pep8 fixes in symbolic (E305 and others)
1 parent 3230f00 commit f418290

File tree

5 files changed

+720
-682
lines changed

5 files changed

+720
-682
lines changed

src/sage/symbolic/callable.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,15 @@
6060
...
6161
SyntaxError: can...t assign to function call...
6262
"""
63-
6463
import sage.rings.abc
6564
from sage.symbolic.ring import SymbolicRing, SR
6665
from sage.categories.pushout import ConstructionFunctor
66+
from sage.structure.factory import UniqueFactory
6767

68-
#########################################################################################
68+
69+
######################################################################
6970
# Callable functions
70-
#########################################################################################
71+
######################################################################
7172
def is_CallableSymbolicExpressionRing(x):
7273
"""
7374
Return ``True`` if ``x`` is a callable symbolic expression ring.
@@ -96,10 +97,10 @@ def is_CallableSymbolicExpressionRing(x):
9697
deprecation(32665, 'is_CallableSymbolicExpressionRing is deprecated; use isinstance(..., sage.rings.abc.CallableSymbolicExpressionRing instead')
9798
return isinstance(x, CallableSymbolicExpressionRing_class)
9899

100+
99101
def is_CallableSymbolicExpression(x):
100102
r"""
101-
Returns ``True`` if ``x`` is a callable symbolic
102-
expression.
103+
Return ``True`` if ``x`` is a callable symbolic expression.
103104
104105
EXAMPLES::
105106
@@ -125,6 +126,7 @@ def is_CallableSymbolicExpression(x):
125126
from sage.structure.element import Expression
126127
return isinstance(x, Expression) and isinstance(x.parent(), CallableSymbolicExpressionRing_class)
127128

129+
128130
class CallableSymbolicExpressionFunctor(ConstructionFunctor):
129131
def __init__(self, arguments):
130132
"""
@@ -157,7 +159,7 @@ def __repr__(self):
157159
sage: CallableSymbolicExpressionFunctor((x,y))
158160
CallableSymbolicExpressionFunctor(x, y)
159161
"""
160-
return "CallableSymbolicExpressionFunctor%s"%repr(self.arguments())
162+
return "CallableSymbolicExpressionFunctor%s" % repr(self.arguments())
161163

162164
def merge(self, other):
163165
"""
@@ -373,9 +375,10 @@ def _repr_(self):
373375

374376
def arguments(self):
375377
"""
376-
Returns the arguments of ``self``. The order that the
377-
variables appear in ``self.arguments()`` is the order that
378-
is used in evaluating the elements of ``self``.
378+
Return the arguments of ``self``.
379+
380+
The order that the variables appear in ``self.arguments()`` is
381+
the order that is used in evaluating the elements of ``self``.
379382
380383
EXAMPLES::
381384
@@ -393,7 +396,7 @@ def arguments(self):
393396

394397
def _repr_element_(self, x):
395398
"""
396-
Returns the string representation of the Expression ``x``.
399+
Return the string representation of the Expression ``x``.
397400
398401
EXAMPLES::
399402
@@ -468,7 +471,7 @@ def _call_element_(self, _the_element, *args, **kwds):
468471
sage: f(z=100)
469472
a + 2*x + 3*y + 100
470473
"""
471-
if any(type(arg).__module__ == 'numpy' and type(arg).__name__ == "ndarray" for arg in args): # avoid importing
474+
if any(type(arg).__module__ == 'numpy' and type(arg).__name__ == "ndarray" for arg in args): # avoid importing
472475
raise NotImplementedError("Numpy arrays are not supported as arguments for symbolic expressions")
473476

474477
d = dict(zip([repr(_) for _ in self.arguments()], args))
@@ -479,7 +482,6 @@ def _call_element_(self, _the_element, *args, **kwds):
479482
__reduce__ = object.__reduce__
480483

481484

482-
from sage.structure.factory import UniqueFactory
483485
class CallableSymbolicExpressionRingFactory(UniqueFactory):
484486
def create_key(self, args, check=True):
485487
"""
@@ -501,8 +503,7 @@ def create_key(self, args, check=True):
501503

502504
def create_object(self, version, key, **extra_args):
503505
"""
504-
Returns a CallableSymbolicExpressionRing given a version and a
505-
key.
506+
Return a CallableSymbolicExpressionRing given a version and a key.
506507
507508
EXAMPLES::
508509
@@ -512,4 +513,5 @@ def create_object(self, version, key, **extra_args):
512513
"""
513514
return CallableSymbolicExpressionRing_class(key)
514515

516+
515517
CallableSymbolicExpressionRing = CallableSymbolicExpressionRingFactory('sage.symbolic.callable.CallableSymbolicExpressionRing')

src/sage/symbolic/constants.py

Lines changed: 44 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -220,27 +220,27 @@
220220
from sage.rings.infinity import (infinity, minus_infinity,
221221
unsigned_infinity)
222222
from sage.structure.richcmp import richcmp_method, op_EQ, op_GE, op_LE
223+
from sage.symbolic.expression import register_symbol, init_pynac_I
224+
from sage.symbolic.expression import E
223225

224226
constants_table = {}
225227
constants_name_table = {}
226228
constants_name_table[repr(infinity)] = infinity
227229
constants_name_table[repr(unsigned_infinity)] = unsigned_infinity
228230
constants_name_table[repr(minus_infinity)] = minus_infinity
229231

230-
from sage.symbolic.expression import register_symbol, init_pynac_I
231-
232232
I = init_pynac_I()
233233

234-
register_symbol(infinity, {'maxima':'inf'}, 0)
235-
register_symbol(minus_infinity, {'maxima':'minf'}, 0)
236-
register_symbol(unsigned_infinity, {'maxima':'infinity'}, 0)
237-
register_symbol(I, {'mathematica':'I'}, 0)
238-
register_symbol(True, {'giac':'true',
239-
'mathematica':'True',
240-
'maxima':'true'}, 0)
241-
register_symbol(False, {'giac':'false',
242-
'mathematica':'False',
243-
'maxima':'false'}, 0)
234+
register_symbol(infinity, {'maxima': 'inf'}, 0)
235+
register_symbol(minus_infinity, {'maxima': 'minf'}, 0)
236+
register_symbol(unsigned_infinity, {'maxima': 'infinity'}, 0)
237+
register_symbol(I, {'mathematica': 'I'}, 0)
238+
register_symbol(True, {'giac': 'true',
239+
'mathematica': 'True',
240+
'maxima': 'true'}, 0)
241+
register_symbol(False, {'giac': 'false',
242+
'mathematica': 'False',
243+
'maxima': 'false'}, 0)
244244

245245

246246
def unpickle_Constant(class_name, name, conversions, latex, mathml, domain):
@@ -271,6 +271,7 @@ def unpickle_Constant(class_name, name, conversions, latex, mathml, domain):
271271
cls = globals()[class_name]
272272
return cls(name=name)
273273

274+
274275
@richcmp_method
275276
class Constant():
276277
def __init__(self, name, conversions=None, latex=None, mathml="",
@@ -290,8 +291,8 @@ def __init__(self, name, conversions=None, latex=None, mathml="",
290291
self._domain = domain
291292

292293
for system, value in self._conversions.items():
293-
setattr(self, "_%s_"%system, partial(self._generic_interface, value))
294-
setattr(self, "_%s_init_"%system, partial(self._generic_interface_init, value))
294+
setattr(self, "_%s_" % system, partial(self._generic_interface, value))
295+
setattr(self, "_%s_init_" % system, partial(self._generic_interface_init, value))
295296

296297
from .expression import PynacConstant
297298
self._pynac = PynacConstant(self._name, self._latex, self._domain)
@@ -510,7 +511,7 @@ def _interface_(self, I):
510511
pass
511512

512513
try:
513-
return getattr(self, "_%s_"%(I.name()))(I)
514+
return getattr(self, "_%s_" % (I.name()))(I)
514515
except AttributeError:
515516
pass
516517

@@ -529,7 +530,7 @@ def _gap_(self, gap):
529530
sage: gap(p)
530531
p
531532
"""
532-
return gap('"%s"'%self)
533+
return gap('"%s"' % self)
533534

534535
def _singular_(self, singular):
535536
"""
@@ -546,7 +547,7 @@ def _singular_(self, singular):
546547
sage: singular(p)
547548
p
548549
"""
549-
return singular('"%s"'%self)
550+
return singular('"%s"' % self)
550551

551552

552553
class Pi(Constant):
@@ -598,7 +599,7 @@ def _real_double_(self, R):
598599

599600
def _sympy_(self):
600601
"""
601-
Converts pi to sympy pi.
602+
Convert pi to sympy pi.
602603
603604
EXAMPLES::
604605
@@ -609,6 +610,7 @@ def _sympy_(self):
609610
import sympy
610611
return sympy.pi
611612

613+
612614
pi = Pi().expression()
613615

614616
"""
@@ -687,12 +689,12 @@ def _sympy_(self):
687689
# The base of the natural logarithm, e, is not a constant in GiNaC/Sage. It is
688690
# represented by exp(1). A dummy class to make this work with arithmetic and
689691
# coercion is implemented in the module sage.symbolic.expression for speed.
690-
from sage.symbolic.expression import E
691692
e = E()
692693

693694
# Allow for backtranslation to this symbol from Mathematica (#29833).
694695
register_symbol(e, {'mathematica': 'E'})
695696

697+
696698
class NotANumber(Constant):
697699
"""
698700
Not a Number
@@ -704,7 +706,7 @@ def __init__(self, name="NaN"):
704706
sage: loads(dumps(NaN))
705707
NaN
706708
"""
707-
conversions=dict(matlab='NaN')
709+
conversions = dict(matlab='NaN')
708710
Constant.__init__(self, name, conversions=conversions)
709711

710712
def __float__(self):
@@ -716,7 +718,7 @@ def __float__(self):
716718
"""
717719
return float('nan')
718720

719-
def _mpfr_(self,R):
721+
def _mpfr_(self, R):
720722
"""
721723
EXAMPLES::
722724
@@ -725,7 +727,7 @@ def _mpfr_(self,R):
725727
sage: type(_)
726728
<class 'sage.rings.real_mpfr.RealNumber'>
727729
"""
728-
return R('NaN') #??? nan in mpfr: void mpfr_set_nan (mpfr_t x)
730+
return R('NaN') # ??? nan in mpfr: void mpfr_set_nan (mpfr_t x)
729731

730732
def _real_double_(self, R):
731733
"""
@@ -751,8 +753,10 @@ def _sympy_(self):
751753
import sympy
752754
return sympy.nan
753755

756+
754757
NaN = NotANumber().expression()
755758

759+
756760
class GoldenRatio(Constant):
757761
"""
758762
The number (1+sqrt(5))/2
@@ -806,7 +810,7 @@ def __float__(self):
806810
sage: golden_ratio.__float__()
807811
1.618033988749895
808812
"""
809-
return float(0.5)*(float(1.0)+math.sqrt(float(5.0)))
813+
return 0.5 + math.sqrt(1.25)
810814

811815
def _real_double_(self, R):
812816
"""
@@ -817,7 +821,7 @@ def _real_double_(self, R):
817821
"""
818822
return R('1.61803398874989484820458')
819823

820-
def _mpfr_(self,R):
824+
def _mpfr_(self, R):
821825
"""
822826
EXAMPLES::
823827
@@ -826,7 +830,7 @@ def _mpfr_(self,R):
826830
sage: RealField(100)(golden_ratio)
827831
1.6180339887498948482045868344
828832
"""
829-
return (R(1)+R(5).sqrt())/R(2)
833+
return (R(1) + R(5).sqrt()) / R(2)
830834

831835
def _algebraic_(self, field):
832836
"""
@@ -853,8 +857,10 @@ def _sympy_(self):
853857
import sympy
854858
return sympy.GoldenRatio
855859

860+
856861
golden_ratio = GoldenRatio().expression()
857862

863+
858864
class Log2(Constant):
859865
"""
860866
The natural logarithm of the real number 2.
@@ -918,7 +924,7 @@ def _real_double_(self, R):
918924
"""
919925
return R.log2()
920926

921-
def _mpfr_(self,R):
927+
def _mpfr_(self, R):
922928
"""
923929
EXAMPLES::
924930
@@ -929,8 +935,10 @@ def _mpfr_(self,R):
929935
"""
930936
return R.log2()
931937

938+
932939
log2 = Log2().expression()
933940

941+
934942
class EulerGamma(Constant):
935943
"""
936944
The limiting difference between the harmonic series and the natural
@@ -964,7 +972,7 @@ def __init__(self, name='euler_gamma'):
964972
Constant.__init__(self, name, conversions=conversions,
965973
latex=r'\gamma', domain='positive')
966974

967-
def _mpfr_(self,R):
975+
def _mpfr_(self, R):
968976
"""
969977
EXAMPLES::
970978
@@ -1006,8 +1014,10 @@ def _sympy_(self):
10061014
import sympy
10071015
return sympy.EulerGamma
10081016

1017+
10091018
euler_gamma = EulerGamma().expression()
10101019

1020+
10111021
class Catalan(Constant):
10121022
"""
10131023
A number appearing in combinatorics defined as the Dirichlet beta
@@ -1025,7 +1035,7 @@ def __init__(self, name='catalan'):
10251035
sage: loads(dumps(catalan))
10261036
catalan
10271037
"""
1028-
#kash: R is default prec
1038+
# kash: R is default prec
10291039
conversions = dict(mathematica='Catalan', kash='Catalan(R)',
10301040
maple='Catalan', maxima='catalan',
10311041
pynac='Catalan')
@@ -1074,8 +1084,10 @@ def _sympy_(self):
10741084
import sympy
10751085
return sympy.Catalan
10761086

1087+
10771088
catalan = Catalan().expression()
10781089

1090+
10791091
class Khinchin(Constant):
10801092
"""
10811093
The geometric mean of the continued fraction expansion of any
@@ -1126,8 +1138,10 @@ def __float__(self):
11261138
"""
11271139
return 2.6854520010653064453097148355
11281140

1141+
11291142
khinchin = Khinchin().expression()
11301143

1144+
11311145
class TwinPrime(Constant):
11321146
r"""
11331147
The Twin Primes constant is defined as
@@ -1173,6 +1187,7 @@ def __float__(self):
11731187
"""
11741188
return 0.66016181584686957392781211001
11751189

1190+
11761191
twinprime = TwinPrime().expression()
11771192

11781193

@@ -1222,6 +1237,7 @@ def __float__(self):
12221237
"""
12231238
return 0.26149721284764278375542683861
12241239

1240+
12251241
mertens = Mertens().expression()
12261242

12271243

0 commit comments

Comments
 (0)