Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pep8 cleanup in repl/ and sat/ #39055

Merged
merged 1 commit into from
Dec 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/sage/repl/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@
sage: 'sage: [False, True]' in output # needs pexpect
True
"""

#*****************************************************************************
# ****************************************************************************
# Copyright (C) 2016 Volker Braun <vbraun.name@gmail.com>
#
# Distributed under the terms of the GNU General Public License (GPL)
# as published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
# http://www.gnu.org/licenses/
#*****************************************************************************
# https://www.gnu.org/licenses/
# ****************************************************************************


import sys
Expand Down
3 changes: 2 additions & 1 deletion src/sage/repl/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,8 @@ def __init__(self, app):
contact_email = 'sage-support@googlegroups.com'
bug_tracker = 'https://github.com/sagemath/sage/issues'
CrashHandler.__init__(self,
app, contact_name, contact_email, bug_tracker, show_crash_traceback=True)
app, contact_name, contact_email,
bug_tracker, show_crash_traceback=True)
self.crash_report_fname = 'Sage_crash_report.txt'


Expand Down
4 changes: 2 additions & 2 deletions src/sage/repl/ipython_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def display(self, args):
max_width = 0
if max_width <= 0:
raise ValueError(
"max width must be a positive integer")
"max width must be a positive integer")
import sage.typeset.character_art as character_art
character_art.MAX_WIDTH = max_width
dm.preferences.text = arg0
Expand Down Expand Up @@ -435,7 +435,7 @@ def __init__(self, shell=None):
self.init_line_transforms()

try:
import sage.all # until sage's import hell is fixed
import sage.all # until sage's import hell is fixed
except ImportError:
import sage.all__sagemath_repl

Expand Down
8 changes: 4 additions & 4 deletions src/sage/repl/rich_output/backend_doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
The Sage display manager using the doctest backend
"""

#*****************************************************************************
# ****************************************************************************
# Copyright (C) 2015 Volker Braun <vbraun.name@gmail.com>
#
# Distributed under the terms of the GNU General Public License (GPL)
# as published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
# http://www.gnu.org/licenses/
#*****************************************************************************
# https://www.gnu.org/licenses/
# ****************************************************************************

import sys

Expand Down Expand Up @@ -295,7 +295,7 @@ def validate(self, rich_output):
assert data.startswith(b'\0\0\0')
# See http://www.ftyps.com/
ftyps = [data[i:i+4] for i in range(8, data[3], 4)]
del ftyps[1] # version number, not an ftyp
del ftyps[1] # version number, not an ftyp
expected = [b'avc1', b'iso2', b'mp41', b'mp42']
assert any(i in ftyps for i in expected)
elif isinstance(rich_output, OutputVideoFlash):
Expand Down
16 changes: 8 additions & 8 deletions src/sage/repl/rich_output/backend_ipython.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ def displayhook(self, plain_text, rich_output):
elif isinstance(rich_output, OutputLatex):
return ({'text/latex': rich_output.latex.get_str(),
'text/plain': plain_text.text.get_str(),
}, {})
}, {})
elif isinstance(rich_output, OutputHtml):
data = {'text/html': rich_output.html.get_str(),
'text/plain': plain_text.text.get_str()}
Expand All @@ -535,29 +535,29 @@ def displayhook(self, plain_text, rich_output):
elif isinstance(rich_output, OutputImagePng):
return ({'image/png': rich_output.png.get(),
'text/plain': plain_text.text.get_str(),
}, {})
}, {})
elif isinstance(rich_output, OutputImageGif):
return ({'text/html': rich_output.html_fragment(),
'text/plain': plain_text.text.get_str(),
}, {})
}, {})
elif isinstance(rich_output, OutputImageJpg):
return ({'image/jpeg': rich_output.jpg.get(),
'text/plain': plain_text.text.get_str(),
}, {})
}, {})
elif isinstance(rich_output, OutputImageSvg):
return ({'image/svg+xml': rich_output.svg.get(),
'text/plain': plain_text.text.get_str(),
}, {})
}, {})
elif isinstance(rich_output, OutputImagePdf):
return ({'image/png': rich_output.png.get(),
'text/plain': plain_text.text.get_str(),
}, {})
}, {})
elif isinstance(rich_output, OutputSceneJmol):
from sage.repl.display.jsmol_iframe import JSMolHtml
jsmol = JSMolHtml(rich_output, height=500)
return ({'text/html': jsmol.iframe(),
'text/plain': plain_text.text.get_str(),
}, {})
}, {})
elif isinstance(rich_output, OutputSceneThreejs):
escaped_html = html.escape(rich_output.html.get_str())
iframe = IFRAME_TEMPLATE.format(
Expand All @@ -567,7 +567,7 @@ def displayhook(self, plain_text, rich_output):
)
return ({'text/html': iframe,
'text/plain': plain_text.text.get_str(),
}, {})
}, {})
else:
raise TypeError('rich_output type not supported')

Expand Down
6 changes: 3 additions & 3 deletions src/sage/repl/rich_output/output_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ class is independent of user preferences and of the display
file system.
"""

#*****************************************************************************
# ****************************************************************************
# Copyright (C) 2015 Volker Braun <vbraun.name@gmail.com>
#
# Distributed under the terms of the GNU General Public License (GPL)
# as published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
# http://www.gnu.org/licenses/
#*****************************************************************************
# https://www.gnu.org/licenses/
# ****************************************************************************


from sage.structure.sage_object import SageObject
Expand Down
6 changes: 3 additions & 3 deletions src/sage/repl/rich_output/output_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
If you define another output type then you must add it to the imports here.
"""

#*****************************************************************************
# ****************************************************************************
# Copyright (C) 2015 Volker Braun <vbraun.name@gmail.com>
#
# Distributed under the terms of the GNU General Public License (GPL)
# as published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
# http://www.gnu.org/licenses/
#*****************************************************************************
# https://www.gnu.org/licenses/
# ****************************************************************************


from .output_basic import (
Expand Down
6 changes: 3 additions & 3 deletions src/sage/repl/rich_output/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
TestOutputPlainText container
"""

#*****************************************************************************
# ****************************************************************************
# Copyright (C) 2015 Volker Braun <vbraun.name@gmail.com>
#
# Distributed under the terms of the GNU General Public License (GPL)
# as published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
# http://www.gnu.org/licenses/
#*****************************************************************************
# https://www.gnu.org/licenses/
# ****************************************************************************


from sage.structure.sage_object import SageObject
Expand Down
4 changes: 2 additions & 2 deletions src/sage/sat/boolean_polynomials.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@
if S[0] is None:
return None
elif S[-1] is False:
return S[0:-1]
return S[0:-1]

Check warning on line 306 in src/sage/sat/boolean_polynomials.py

View check run for this annotation

Codecov / codecov/patch

src/sage/sat/boolean_polynomials.py#L306

Added line #L306 was not covered by tests
return S


Expand Down Expand Up @@ -395,7 +395,7 @@
try:
lc = solver.learnt_clauses()
except (AttributeError, NotImplementedError):
# solver does not support recovering learnt clauses
# solver does not support recovering learnt clauses
lc = []
for c in lc:
if len(c) <= max_learnt_length:
Expand Down
30 changes: 15 additions & 15 deletions src/sage/sat/converters/polybori.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
self.cutting_number = cutting_number

if use_xor_clauses is None:
use_xor_clauses = hasattr(solver,"add_xor_clause")
use_xor_clauses = hasattr(solver, "add_xor_clause")
self.use_xor_clauses = use_xor_clauses

self.ring = ring
Expand Down Expand Up @@ -222,7 +222,7 @@
indices.append(nav.value())
nav = t
else:
if self.random_generator.randint(0,1):
if self.random_generator.randint(0, 1):
indices.append(nav.value())
nav = t

Expand Down Expand Up @@ -337,11 +337,11 @@
for fpart, this_equal_zero in self.split_xor(f, equal_zero):
ll = len(fpart)
for p in self.permutations(ll, this_equal_zero):
self.solver.add_clause([ p[i]*fpart[i] for i in range(ll) ])
self.solver.add_clause([p[i] * fpart[i] for i in range(ll)])

Check warning on line 340 in src/sage/sat/converters/polybori.py

View check run for this annotation

Codecov / codecov/patch

src/sage/sat/converters/polybori.py#L340

Added line #L340 was not covered by tests
else:
ll = len(f)
for p in self.permutations(ll, equal_zero):
self.solver.add_clause([ p[i]*f[i] for i in range(ll) ])
self.solver.add_clause([p[i] * f[i] for i in range(ll)])

@cached_method
def monomial(self, m):
Expand Down Expand Up @@ -387,19 +387,19 @@
For correctness, this function is cached.
"""
if m.deg() == 1:
return m.index()+1
else:
# we need to encode the relationship between the monomial
# and its variables
variables = [self.monomial(v) for v in m.variables()]
monomial = self.var(m)
return m.index() + 1

# (a | -w) & (b | -w) & (w | -a | -b) <=> w == a*b
for v in variables:
self.solver.add_clause( (v, -monomial) )
self.solver.add_clause( tuple([monomial] + [-v for v in variables]) )
# we need to encode the relationship between the monomial
# and its variables
variables = [self.monomial(v) for v in m.variables()]
monomial = self.var(m)

# (a | -w) & (b | -w) & (w | -a | -b) <=> w == a*b
for v in variables:
self.solver.add_clause((v, -monomial))
self.solver.add_clause(tuple([monomial] + [-v for v in variables]))

return monomial
return monomial

@cached_function
def permutations(length, equal_zero):
Expand Down
4 changes: 2 additions & 2 deletions src/sage/sat/solvers/picosat.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ def __call__(self, assumptions=None):
sage: solver() # optional - pycosat
False
"""
#import pycosat
#self._solve = pycosat.solve
# import pycosat
# self._solve = pycosat.solve
sol = self._solve(self._clauses, verbose=self._verbosity,
prop_limit=self._prop_limit, vars=self._nvars)
# sol = pycosat.solve(self._clauses)
Expand Down
4 changes: 2 additions & 2 deletions src/sage/sat/solvers/sat_lp.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def var(self):
nvars = n = self._LP.number_of_variables()
while nvars == self._LP.number_of_variables():
n += 1
self._vars[n] # creates the variable if needed
self._vars[n] # creates the variable if needed
return n

def nvars(self):
Expand Down Expand Up @@ -143,7 +143,7 @@ def __call__(self):

b = self._LP.get_values(self._vars, convert=bool, tolerance=self._integrality_tolerance)
n = max(b)
return [None]+[b.get(i, False) for i in range(1,n+1)]
return [None] + [b.get(i, False) for i in range(1, n + 1)]

def __repr__(self):
"""
Expand Down
6 changes: 3 additions & 3 deletions src/sage/stats/distributions/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@

sage: from sage.stats.distributions.catalog import *
"""
#*****************************************************************************
# ****************************************************************************
# Copyright (C) 2024 Gareth Ma <grhkm21@gmail.com>
#
# Distributed under the terms of the GNU General Public License (GPL),
# version 2 or later (at your preference).
#
# http://www.gnu.org/licenses/
#*****************************************************************************
# https://www.gnu.org/licenses/
# ****************************************************************************

from sage.misc.lazy_import import lazy_import
lazy_import("sage.stats.distributions.discrete_gaussian_integer", ["DiscreteGaussianDistributionIntegerSampler"])
Expand Down
Loading