Skip to content

Commit 397d973

Browse files
Merge pull request #211 from GiacomoPope/linting_fixes
Small changes to please cython-lint
2 parents be0e410 + 5c75f51 commit 397d973

24 files changed

+137
-144
lines changed

pyproject.toml

+18-1
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,25 @@ requires = ["meson-python>=0.13", "cython>=3.0,<3.1"]
4040
build-backend = "mesonpy"
4141

4242
[tool.cython-lint]
43+
# E129 visually indented line with same indent as next logical line
44+
# Reasoning: this rule is a little controversial
45+
# (see https://github.com/PyCQA/pycodestyle/issues/386)
46+
# and we ignore it to avoid needing additional indentation after
47+
# long logical statements.
48+
#
49+
# E501 line too long (128 > 120 characters)
50+
# Reasoning: this is a work in progress and will be enforced once a line length
51+
# and refactor has taken place. See issue #214
52+
#
53+
# E741 ambiguous variable name
54+
# Reasoning: many places it makes sense to use l or other letters as variable
55+
# names as it is standard in mathematical notation.
56+
#
57+
# E743 ambiguous function definition
58+
# Reasoning: this is a work in progress and will be enforced after #210 is
59+
# resolved.
4360
max-line-length = 120
44-
ignore = ['E128','E129','E202','E221','E222','E261','E262','E265','E501','E731','E741','E743']
61+
ignore = ['E129','E501','E741','E743']
4562
exclude = 'src/flint/flintlib/.*'
4663

4764
[tool.spin]

src/flint/flint_base/flint_base.pyx

+3-1
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,9 @@ cdef class flint_mat(flint_elem):
780780
def repr(self):
781781
# XXX
782782
return "%s(%i, %i, [%s])" % (type(self).__name__,
783-
self.nrows(), self.ncols(), (", ".join(map(str, self.entries()))))
783+
self.nrows(),
784+
self.ncols(),
785+
", ".join(map(str, self.entries())))
784786

785787
def str(self, *args, **kwargs):
786788
tab = self.table()

src/flint/functions/showgood.pyx

+3-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ cdef goodstr(x):
3838

3939

4040
def good(func, slong prec=0, slong maxprec=0, slong dps=0,
41-
slong maxdps=0, slong padding=10, bint verbose=False, bint show=False, bint parts=True, metric=None):
41+
slong maxdps=0, slong padding=10, bint verbose=False,
42+
bint show=False, bint parts=True, metric=None):
4243
"""
4344
Evaluates *func*, automatically increasing the precision to get
4445
a result accurate to the current working precision (or the
@@ -81,7 +82,7 @@ def good(func, slong prec=0, slong maxprec=0, slong dps=0,
8182
maxprec = 10 * prec + 100
8283

8384
if metric == "abssum":
84-
metric = lambda L: sum(abs(c) for c in L)
85+
def metric(L): return sum(abs(c) for c in L)
8586

8687
# for printing
8788
if dps == 0:

src/flint/test/test_all.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1921,7 +1921,7 @@ def test_fmpz_mod_poly():
19211921
R_other = fmpz_mod_poly_ctx(F_other)
19221922

19231923
assert raises(lambda: fmpz_mod_poly(1, "A"), TypeError) # Need a valid context
1924-
assert raises(lambda: R(R_other([1,2,3])), ValueError), f"{R(R_other([1,2,3])) = }" # moduli must match
1924+
assert raises(lambda: R(R_other([1,2,3])), ValueError) # moduli must match
19251925
assert raises(lambda: R(F_other(2)), ValueError) # moduli must match
19261926
assert raises(lambda: R([F(1), F_other(2)]), ValueError) # moduli must match
19271927
assert raises(lambda: R([F(1), "A"]), TypeError) # need to be able to cast to fmpz_mod
@@ -2120,7 +2120,7 @@ def test_fmpz_mod_poly():
21202120
assert raises(lambda: f % f_bad, ValueError)
21212121
assert raises(lambda: 123 % f_bad, DomainError)
21222122
assert raises(lambda: f % "AAA", TypeError)
2123-
assert raises(lambda: tuple() % f, TypeError), f'{"AAA" % f = }'
2123+
assert raises(lambda: tuple() % f, TypeError)
21242124

21252125
assert f % 1 == 0
21262126
assert R_test.one() % 1 == 0
@@ -2550,7 +2550,7 @@ def test_polys():
25502550
assert P([S(1)]) == P([1]) == P(P([1])) == P(1)
25512551

25522552
assert raises(lambda: P([None]), TypeError)
2553-
assert raises(lambda: P(object()), TypeError), f"{P(object()) = }"
2553+
assert raises(lambda: P(object()), TypeError)
25542554
assert raises(lambda: P(None), TypeError)
25552555
assert raises(lambda: P(None, None), TypeError)
25562556
assert raises(lambda: P([1,2], None), TypeError)
@@ -2903,7 +2903,7 @@ def quick_poly():
29032903
assert ctx.constant(1) == mpoly({(0, 0): 1}) == P(1, ctx=ctx)
29042904

29052905
assert raises(lambda: P([None]), TypeError)
2906-
assert raises(lambda: P(object()), TypeError), f"{P(object()) = }"
2906+
assert raises(lambda: P(object()), TypeError)
29072907
assert raises(lambda: P(None), TypeError)
29082908
assert raises(lambda: P(None, None), TypeError)
29092909
assert raises(lambda: P([1,2], None), TypeError)

src/flint/types/acb.pyx

+9-18
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,6 @@ cdef any_as_acb_or_notimplemented(x):
8888
return t
8989

9090

91-
# cdef any_as_arb_or_acb(x):
92-
# if typecheck(x, arb) or typecheck(x, acb):
93-
# return x
94-
# try:
95-
# return arb(x)
96-
# except (TypeError, ValueError):
97-
# return acb(x)
98-
99-
10091
# Copied with modifications from sage/rings/complex_arb.pyx
10192
@cython.internal
10293
cdef class IntegrationContext:
@@ -1210,7 +1201,7 @@ cdef class acb(flint_scalar):
12101201
T3 = _acb_vec_init(r + 3)
12111202
T4 = _acb_vec_init(r + 4)
12121203
acb_modular_theta_jet(T1, T2, T3, T4,
1213-
(<acb>z).val, (<acb>tau).val, r + 1, getprec())
1204+
(<acb>z).val, (<acb>tau).val, r + 1, getprec())
12141205
acb_set((<acb>t1).val, T1 + r)
12151206
acb_set((<acb>t2).val, T2 + r)
12161207
acb_set((<acb>t3).val, T3 + r)
@@ -1556,7 +1547,7 @@ cdef class acb(flint_scalar):
15561547
if abc:
15571548
flags |= 16
15581549
acb_hypgeom_2f1((<acb>u).val, (<acb>a).val, (<acb>b).val, (<acb>c).val,
1559-
(<acb>self).val, flags, getprec())
1550+
(<acb>self).val, flags, getprec())
15601551
return u
15611552

15621553
def chebyshev_t(s, n):
@@ -1764,7 +1755,7 @@ cdef class acb(flint_scalar):
17641755
w = acb.__new__(acb)
17651756
z = acb.__new__(acb)
17661757
acb_hypgeom_airy((<acb>u).val, (<acb>v).val,
1767-
(<acb>w).val, (<acb>z).val, (<acb>s).val, getprec())
1758+
(<acb>w).val, (<acb>z).val, (<acb>s).val, getprec())
17681759
return u, v, w, z
17691760

17701761
def lambertw(s, branch=0, bint left=False, bint middle=False):
@@ -2621,9 +2612,9 @@ cdef class acb(flint_scalar):
26212612

26222613
@staticmethod
26232614
def integral(func, a, b, params=None,
2624-
rel_tol=None, abs_tol=None,
2625-
deg_limit=None, eval_limit=None, depth_limit=None,
2626-
use_heap=None, verbose=None):
2615+
rel_tol=None, abs_tol=None,
2616+
deg_limit=None, eval_limit=None, depth_limit=None,
2617+
use_heap=None, verbose=None):
26272618
r"""
26282619
Computes the integral `\int_a^b f(x) dx` where the integrand
26292620
*f* is defined by *func*.
@@ -2752,7 +2743,7 @@ cdef class acb(flint_scalar):
27522743
Hpos = acb.__new__(acb)
27532744
Hneg = acb.__new__(acb)
27542745
acb_hypgeom_coulomb((<acb>F).val, (<acb>G).val, (<acb>Hpos).val, (<acb>Hneg).val,
2755-
(<acb>l).val, (<acb>eta).val, (<acb>self).val, getprec())
2746+
(<acb>l).val, (<acb>eta).val, (<acb>self).val, getprec())
27562747
return F, G, Hpos, Hneg
27572748

27582749
def coulomb_f(self, l, eta):
@@ -2768,7 +2759,7 @@ cdef class acb(flint_scalar):
27682759
eta = any_as_acb(eta)
27692760
F = acb.__new__(acb)
27702761
acb_hypgeom_coulomb((<acb>F).val, NULL, NULL, NULL,
2771-
(<acb>l).val, (<acb>eta).val, (<acb>self).val, getprec())
2762+
(<acb>l).val, (<acb>eta).val, (<acb>self).val, getprec())
27722763
return F
27732764

27742765
def coulomb_g(self, l, eta):
@@ -2784,5 +2775,5 @@ cdef class acb(flint_scalar):
27842775
eta = any_as_acb(eta)
27852776
G = acb.__new__(acb)
27862777
acb_hypgeom_coulomb(NULL, (<acb>G).val, NULL, NULL,
2787-
(<acb>l).val, (<acb>eta).val, (<acb>self).val, getprec())
2778+
(<acb>l).val, (<acb>eta).val, (<acb>self).val, getprec())
27882779
return G

src/flint/types/acb_mat.pyx

+7-7
Original file line numberDiff line numberDiff line change
@@ -775,29 +775,29 @@ cdef class acb_mat(flint_mat):
775775
if n != 0:
776776
if algorithm == "approx":
777777
acb_mat_approx_eig_qr(acb_mat_entry(E.val, 0, 0),
778-
LP, RP, s.val, magp, maxiter, getprec())
778+
LP, RP, s.val, magp, maxiter, getprec())
779779
else:
780780
acb_mat_approx_eig_qr(acb_mat_entry(E.val, 0, 0),
781-
NULL, RP, s.val, magp, maxiter, getprec())
781+
NULL, RP, s.val, magp, maxiter, getprec())
782782
if multiple:
783783
if left or right:
784784
raise NotImplementedError("eigenvectors not supported with multiple=True")
785785
if algorithm == "rump":
786786
success = acb_mat_eig_multiple_rump(acb_mat_entry(E.val, 0, 0),
787-
s.val, acb_mat_entry(E.val, 0, 0), RP, prec)
787+
s.val, acb_mat_entry(E.val, 0, 0), RP, prec)
788788
else:
789789
success = acb_mat_eig_multiple(acb_mat_entry(E.val, 0, 0),
790-
s.val, acb_mat_entry(E.val, 0, 0), RP, prec)
790+
s.val, acb_mat_entry(E.val, 0, 0), RP, prec)
791791
else:
792792
if algorithm == "rump":
793793
success = acb_mat_eig_simple_rump(acb_mat_entry(E.val, 0, 0),
794-
LP, RP, s.val, acb_mat_entry(E.val, 0, 0), RP, prec)
794+
LP, RP, s.val, acb_mat_entry(E.val, 0, 0), RP, prec)
795795
elif algorithm == "vdhoeven_mourrain":
796796
success = acb_mat_eig_simple_vdhoeven_mourrain(acb_mat_entry(E.val, 0, 0),
797-
LP, RP, s.val, acb_mat_entry(E.val, 0, 0), RP, prec)
797+
LP, RP, s.val, acb_mat_entry(E.val, 0, 0), RP, prec)
798798
else:
799799
success = acb_mat_eig_simple(acb_mat_entry(E.val, 0, 0),
800-
LP, RP, s.val, acb_mat_entry(E.val, 0, 0), RP, prec)
800+
LP, RP, s.val, acb_mat_entry(E.val, 0, 0), RP, prec)
801801
if not (nonstop or success):
802802
raise ValueError("failed to isolate eigenvalues (try higher prec, multiple=True for multiple eigenvalues, or nonstop=True to avoid the exception)")
803803
if tol is not None:

src/flint/types/acb_poly.pyx

+4-4
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ cdef class acb_poly(flint_poly):
197197
return u
198198

199199
def __pos__(self):
200-
return self # ?
200+
return self # ?
201201

202202
def __neg__(s):
203203
u = acb_poly.__new__(acb_poly)
@@ -261,7 +261,7 @@ cdef class acb_poly(flint_poly):
261261
q = acb_poly.__new__(acb_poly)
262262
r = acb_poly.__new__(acb_poly)
263263
if acb_poly_divrem((<acb_poly>q).val, (<acb_poly>r).val,
264-
(<acb_poly>s).val, (<acb_poly>t).val, getprec()):
264+
(<acb_poly>s).val, (<acb_poly>t).val, getprec()):
265265
return q
266266
else:
267267
raise ZeroDivisionError("acb_poly leading coefficient must be nonzero")
@@ -281,7 +281,7 @@ cdef class acb_poly(flint_poly):
281281
q = acb_poly.__new__(acb_poly)
282282
r = acb_poly.__new__(acb_poly)
283283
if acb_poly_divrem((<acb_poly>q).val, (<acb_poly>r).val,
284-
(<acb_poly>s).val, (<acb_poly>t).val, getprec()):
284+
(<acb_poly>s).val, (<acb_poly>t).val, getprec()):
285285
return r
286286
else:
287287
raise ZeroDivisionError("acb_poly leading coefficient must be nonzero")
@@ -301,7 +301,7 @@ cdef class acb_poly(flint_poly):
301301
q = acb_poly.__new__(acb_poly)
302302
r = acb_poly.__new__(acb_poly)
303303
if acb_poly_divrem((<acb_poly>q).val, (<acb_poly>r).val,
304-
(<acb_poly>s).val, (<acb_poly>t).val, getprec()):
304+
(<acb_poly>s).val, (<acb_poly>t).val, getprec()):
305305
return q, r
306306
else:
307307
raise ZeroDivisionError("acb_poly leading coefficient must be nonzero")

src/flint/types/acb_series.pyx

+5-4
Original file line numberDiff line numberDiff line change
@@ -731,8 +731,9 @@ cdef class acb_series(flint_series):
731731
G = acb_series.__new__(acb_series)
732732
Hpos = acb_series.__new__(acb_series)
733733
Hneg = acb_series.__new__(acb_series)
734-
acb_hypgeom_coulomb_series((<acb_series>F).val, (<acb_series>G).val, (<acb_series>Hpos).val, (<acb_series>Hneg).val,
735-
(<acb>l).val, (<acb>eta).val, (<acb_series>self).val, cap, getprec())
734+
acb_hypgeom_coulomb_series((<acb_series>F).val, (<acb_series>G).val, (<acb_series>Hpos).val,
735+
(<acb_series>Hneg).val, (<acb>l).val, (<acb>eta).val,
736+
(<acb_series>self).val, cap, getprec())
736737
(<acb_series>F).prec = cap
737738
(<acb_series>G).prec = cap
738739
(<acb_series>Hpos).prec = cap
@@ -747,7 +748,7 @@ cdef class acb_series(flint_series):
747748
cap = min(cap, (<acb_series>self).prec)
748749
F = acb_series.__new__(acb_series)
749750
acb_hypgeom_coulomb_series((<acb_series>F).val, NULL, NULL, NULL,
750-
(<acb>l).val, (<acb>eta).val, (<acb_series>self).val, cap, getprec())
751+
(<acb>l).val, (<acb>eta).val, (<acb_series>self).val, cap, getprec())
751752
(<acb_series>F).prec = cap
752753
return F
753754

@@ -759,7 +760,7 @@ cdef class acb_series(flint_series):
759760
cap = min(cap, (<acb_series>self).prec)
760761
G = acb_series.__new__(acb_series)
761762
acb_hypgeom_coulomb_series(NULL, (<acb_series>G).val, NULL, NULL,
762-
(<acb>l).val, (<acb>eta).val, (<acb_series>self).val, cap, getprec())
763+
(<acb>l).val, (<acb>eta).val, (<acb_series>self).val, cap, getprec())
763764
(<acb_series>G).prec = cap
764765
return G
765766

src/flint/types/arb.pyx

+7-7
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ cdef class arb(flint_scalar):
192192
if rad is not None:
193193
rad = arb(rad)
194194
arb_add_error(self.val, (<arb>rad).val)
195-
#rad = arf(rad)
196-
#arb_add_error_arf(self.val, (<arf>rad).val)
195+
# rad = arf(rad)
196+
# arb_add_error_arf(self.val, (<arf>rad).val)
197197

198198
cpdef bint is_zero(self):
199199
return arb_is_zero(self.val)
@@ -1629,7 +1629,7 @@ cdef class arb(flint_scalar):
16291629
w = arb.__new__(arb)
16301630
z = arb.__new__(arb)
16311631
arb_hypgeom_airy((<arb>u).val, (<arb>v).val,
1632-
(<arb>w).val, (<arb>z).val, (<arb>s).val, getprec())
1632+
(<arb>w).val, (<arb>z).val, (<arb>s).val, getprec())
16331633
return u, v, w, z
16341634

16351635
@staticmethod
@@ -2281,7 +2281,7 @@ cdef class arb(flint_scalar):
22812281
if abc:
22822282
flags |= 16
22832283
arb_hypgeom_2f1((<arb>u).val, (<arb>a).val, (<arb>b).val, (<arb>c).val,
2284-
(<arb>self).val, flags, getprec())
2284+
(<arb>self).val, flags, getprec())
22852285
return u
22862286

22872287
@staticmethod
@@ -2622,7 +2622,7 @@ cdef class arb(flint_scalar):
26222622
F = arb.__new__(arb)
26232623
G = arb.__new__(arb)
26242624
arb_hypgeom_coulomb((<arb>F).val, (<arb>G).val,
2625-
(<arb>l).val, (<arb>eta).val, (<arb>self).val, getprec())
2625+
(<arb>l).val, (<arb>eta).val, (<arb>self).val, getprec())
26262626
return F, G
26272627

26282628
def coulomb_f(self, l, eta):
@@ -2638,7 +2638,7 @@ cdef class arb(flint_scalar):
26382638
eta = any_as_arb(eta)
26392639
F = arb.__new__(arb)
26402640
arb_hypgeom_coulomb((<arb>F).val, NULL,
2641-
(<arb>l).val, (<arb>eta).val, (<arb>self).val, getprec())
2641+
(<arb>l).val, (<arb>eta).val, (<arb>self).val, getprec())
26422642
return F
26432643

26442644
def coulomb_g(self, l, eta):
@@ -2654,5 +2654,5 @@ cdef class arb(flint_scalar):
26542654
eta = any_as_arb(eta)
26552655
G = arb.__new__(arb)
26562656
arb_hypgeom_coulomb(NULL, (<arb>G).val,
2657-
(<arb>l).val, (<arb>eta).val, (<arb>self).val, getprec())
2657+
(<arb>l).val, (<arb>eta).val, (<arb>self).val, getprec())
26582658
return G

src/flint/types/arb_poly.pyx

+4-4
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ cdef class arb_poly(flint_poly):
194194
return u
195195

196196
def __pos__(self):
197-
return self # ?
197+
return self # ?
198198

199199
def __neg__(s):
200200
u = arb_poly.__new__(arb_poly)
@@ -258,7 +258,7 @@ cdef class arb_poly(flint_poly):
258258
q = arb_poly.__new__(arb_poly)
259259
r = arb_poly.__new__(arb_poly)
260260
if arb_poly_divrem((<arb_poly>q).val, (<arb_poly>r).val,
261-
(<arb_poly>s).val, (<arb_poly>t).val, getprec()):
261+
(<arb_poly>s).val, (<arb_poly>t).val, getprec()):
262262
return q
263263
else:
264264
raise ZeroDivisionError("arb_poly leading coefficient must be nonzero")
@@ -278,7 +278,7 @@ cdef class arb_poly(flint_poly):
278278
q = arb_poly.__new__(arb_poly)
279279
r = arb_poly.__new__(arb_poly)
280280
if arb_poly_divrem((<arb_poly>q).val, (<arb_poly>r).val,
281-
(<arb_poly>s).val, (<arb_poly>t).val, getprec()):
281+
(<arb_poly>s).val, (<arb_poly>t).val, getprec()):
282282
return r
283283
else:
284284
raise ZeroDivisionError("arb_poly leading coefficient must be nonzero")
@@ -298,7 +298,7 @@ cdef class arb_poly(flint_poly):
298298
q = arb_poly.__new__(arb_poly)
299299
r = arb_poly.__new__(arb_poly)
300300
if arb_poly_divrem((<arb_poly>q).val, (<arb_poly>r).val,
301-
(<arb_poly>s).val, (<arb_poly>t).val, getprec()):
301+
(<arb_poly>s).val, (<arb_poly>t).val, getprec()):
302302
return q, r
303303
else:
304304
raise ZeroDivisionError("arb_poly leading coefficient must be nonzero")

0 commit comments

Comments
 (0)