Skip to content

Commit

Permalink
sagemathgh-39231: fix and activate some checks in ruff-minimal
Browse files Browse the repository at this point in the history
    
This is fixing some ruff warnings and turning on the corresponding
checks.

### 📝 Checklist

- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.
    
URL: sagemath#39231
Reported by: Frédéric Chapoton
Reviewer(s): Martin Rubey
  • Loading branch information
Release Manager committed Jan 1, 2025
2 parents 8bd510a + 9432af7 commit 21e133c
Show file tree
Hide file tree
Showing 13 changed files with 24 additions and 25 deletions.
3 changes: 2 additions & 1 deletion src/sage/combinat/matrices/latin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1212,7 +1212,8 @@ def disjoint_mate_dlxcpp_rows_and_map(self, allow_subtrade):

dlx_rows.append([c_OFFSET, r_OFFSET, xy_OFFSET])

max_column_nr = max(max_column_nr, max(c_OFFSET, r_OFFSET, xy_OFFSET))
max_column_nr = max(max_column_nr, c_OFFSET,
r_OFFSET, xy_OFFSET)

# We will have missed some columns. We
# have to add 'dummy' rows so that the C++ DLX solver will find
Expand Down
4 changes: 2 additions & 2 deletions src/sage/doctest/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -1351,12 +1351,12 @@ def run_val_gdb(self, testing=False):
opt = self.options

if opt.gdb:
cmd = f'''exec gdb --eval-command="run" --args '''
cmd = '''exec gdb --eval-command="run" --args '''
flags = ""
if opt.logfile:
sage_cmd += f" --logfile {shlex.quote(opt.logfile)}"
elif opt.lldb:
cmd = f'''exec lldb --one-line "process launch" --one-line "cont" -- '''
cmd = '''exec lldb --one-line "process launch" --one-line "cont" -- '''
flags = ""
else:
if opt.logfile is None:
Expand Down
8 changes: 4 additions & 4 deletions src/sage/functions/airy.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def _evalf_(self, x, **kwargs):
from sage.rings.real_mpfr import RR
from sage.rings.cc import CC
from sage.functions.other import real, imag
from scipy.special import airy as airy
from scipy.special import airy
if x in RR:
y = airy(real(x))[0]
if parent is None:
Expand Down Expand Up @@ -341,7 +341,7 @@ def _evalf_(self, x, **kwargs):
from sage.rings.real_mpfr import RR
from sage.rings.cc import CC
from sage.functions.other import real, imag
from scipy.special import airy as airy
from scipy.special import airy
if x in RR:
y = airy(real(x))[1]
if parent is None:
Expand Down Expand Up @@ -680,7 +680,7 @@ def _evalf_(self, x, **kwargs):
from sage.rings.real_mpfr import RR
from sage.rings.cc import CC
from sage.functions.other import real, imag
from scipy.special import airy as airy
from scipy.special import airy
if x in RR:
y = airy(real(x))[2]
if parent is None:
Expand Down Expand Up @@ -782,7 +782,7 @@ def _evalf_(self, x, **kwargs):
from sage.rings.real_mpfr import RR
from sage.rings.cc import CC
from sage.functions.other import real, imag
from scipy.special import airy as airy
from scipy.special import airy
if x in RR:
y = airy(real(x))[3]
if parent is None:
Expand Down
2 changes: 1 addition & 1 deletion src/sage/functions/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
- Tomas Kalvoda (2015-04-01): Add :meth:`exp_polar()` (:issue:`18085`)
"""

from sage.misc.functional import log as log
from sage.misc.functional import log
from sage.misc.lazy_import import lazy_import
from sage.rings.integer import Integer
from sage.rings.integer_ring import ZZ
Expand Down
4 changes: 2 additions & 2 deletions src/sage/graphs/generators/random.py
Original file line number Diff line number Diff line change
Expand Up @@ -1709,7 +1709,7 @@ def RandomKTree(n, k, seed=None):

# A graph with treewidth 0 has no edges
if k == 0:
g = Graph(n, name=f"Random 0-tree")
g = Graph(n, name="Random 0-tree")
return g

if n < k + 1:
Expand Down Expand Up @@ -1803,7 +1803,7 @@ def RandomPartialKTree(n, k, x, seed=None):

# A graph with treewidth 0 has no edges
if k == 0:
g = Graph(n, name=f"Random partial 0-tree")
g = Graph(n, name="Random partial 0-tree")
return g

if n < k + 1:
Expand Down
2 changes: 1 addition & 1 deletion src/sage/misc/package_dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ def handle_file(root, file):
else:
handle_file(*os.path.split(path))

print(f"sage --fixdistributions: checking consistency")
print("sage --fixdistributions: checking consistency")

for package in ordinary_packages:
if len(package_distributions_per_directives[package]) > 1:
Expand Down
2 changes: 1 addition & 1 deletion src/sage/modules/with_basis/representation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1895,7 +1895,7 @@ def __init__(self, rep, degree, **options):
R = rep.base_ring()
dim = rep.dimension()
if degree not in ZZ or degree < 0:
raise ValueError(f"the degree must be a nonnegative integer")
raise ValueError("the degree must be a nonnegative integer")
self._symalg = PolynomialRing(R, 'e', dim)
self._basis_order = list(rep.basis().keys())
G = self._symalg.gens()
Expand Down
3 changes: 1 addition & 2 deletions src/sage/quadratic_forms/quadratic_form__ternary_Tornaria.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ def adjoint(self):
[ * 19 4 ]
[ * * 8 ]
"""
from sage.quadratic_forms.quadratic_form import QuadraticForm as QuadraticForm

from sage.quadratic_forms.quadratic_form import QuadraticForm
if is_odd(self.dim()):
return QuadraticForm(self.matrix().adjoint_classical() * 2)
return QuadraticForm(self.matrix().adjoint_classical())
Expand Down
2 changes: 1 addition & 1 deletion src/sage/schemes/curves/projective_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -2300,7 +2300,7 @@ def __init__(self, A, f):
self._open_affine_index = i
break
else:
assert "no projective curve defined"
raise ValueError("no projective curve defined")

def function_field(self):
"""
Expand Down
7 changes: 4 additions & 3 deletions src/sage/schemes/elliptic_curves/ell_curve_isogeny.py
Original file line number Diff line number Diff line change
Expand Up @@ -3319,12 +3319,13 @@ def dual(self):

else:
# trac 7096
# this should take care of the case when the isogeny is not normalized.
# this should take care of the case when the isogeny is
# not normalized.
u = self.scaling_factor()
E2 = E2pr.change_weierstrass_model(u/F(d), 0, 0, 0)

phi_hat = EllipticCurveIsogeny(E1, None, E2, d)
# assert phi_hat.scaling_factor() == 1
# assert phi_hat.scaling_factor() == 1

for pre_iso in self._codomain.isomorphisms(E1):
for post_iso in E2.isomorphisms(self._domain):
Expand All @@ -3335,7 +3336,7 @@ def dual(self):
continue
break
else:
assert "bug in dual()"
raise RuntimeError("bug in dual()")

phi_hat._set_pre_isomorphism(pre_iso)
phi_hat._set_post_isomorphism(post_iso)
Expand Down
2 changes: 1 addition & 1 deletion src/sage/schemes/elliptic_curves/ell_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -1754,7 +1754,7 @@ def kernel_polynomial_from_divisor(self, f, l, *, check=True):
if not f.is_irreducible():
raise NotImplementedError('currently, kernel_polynomial_from_divisor() only supports irreducible polynomials')
if f.parent().base_ring() != self.base_ring():
raise TypeError(f'given polynomial is not defined over the base ring of the curve')
raise TypeError('given polynomial is not defined over the base ring of the curve')
if self.division_polynomial(l, x=f.parent().quotient_ring(f).gen()):
raise ValueError(f'given polynomial does not divide the {l}-division polynomial')

Expand Down
6 changes: 3 additions & 3 deletions src/sage/tests/arxiv_0812_2725.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
sage: dcrossing([(1,5), (2,4), (4,9), (6,12), (7,10), (10,11)])
3
"""
#*****************************************************************************
# ****************************************************************************
# Copyright (C) 2008 Dan Drake <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
Expand All @@ -34,8 +34,8 @@
# your option) any later version.
#
# See https://www.gnu.org/licenses/.
#*****************************************************************************
from sage.combinat.set_partition import SetPartitions as SetPartitions
# ****************************************************************************
from sage.combinat.set_partition import SetPartitions


def CompleteMatchings(n):
Expand Down
4 changes: 1 addition & 3 deletions src/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -304,16 +304,14 @@ passenv = RUFF_OUTPUT_FORMAT
# 7 E743 [ ] Ambiguous function name: `I`
# 7 PLR0124 [ ] Name compared with itself, consider replacing `a == a`
# 5 PLW0127 [ ] Self-assignment of variable `a`
# 4 F541 [*] f-string without any placeholders
# 4 PLW1508 [ ] Invalid type for environment variable default; expected `str` or `None`
# 3 PLC3002 [ ] Lambda expression called directly. Execute the expression inline instead.
# 2 E742 [ ] Ambiguous class name: `I`
# 2 PLE0302 [ ] The special method `__len__` expects 1 parameter, 3 were given
# 2 PLW0129 [ ] Asserting on a non-empty string literal will always pass
# 1 F402 [ ] Import `factor` from line 259 shadowed by loop variable
# 1 PLC0208 [*] Use a sequence type instead of a `set` when iterating over values
#
commands = ruff check --ignore E402,E721,E731,E741,E742,E743,F401,F402,F403,F405,F541,F811,F821,F841,I001,PLC0206,PLC0208,PLC0414,PLC2401,PLC3002,PLE0302,PLR0124,PLR0402,PLR0911,PLR0912,PLR0913,PLR0915,PLR1704,PLR1711,PLR1714,PLR1736,PLR2004,PLR5501,PLW0120,PLW0127,PLW0129,PLW0211,PLW0602,PLW0603,PLW0642,PLW1508,PLW1510,PLW2901,PLW3301 {posargs:{toxinidir}/sage/}
commands = ruff check --ignore E402,E721,E731,E741,E742,E743,F401,F402,F403,F405,F811,F821,F841,I001,PLC0206,PLC0208,PLC2401,PLC3002,PLE0302,PLR0124,PLR0402,PLR0911,PLR0912,PLR0913,PLR0915,PLR1704,PLR1711,PLR1714,PLR1736,PLR2004,PLR5501,PLW0120,PLW0127,PLW0211,PLW0602,PLW0603,PLW0642,PLW1508,PLW1510,PLW2901,PLW3301 {posargs:{toxinidir}/sage/}

[flake8]
rst-roles =
Expand Down

0 comments on commit 21e133c

Please sign in to comment.