Merge pull request #26311 from edx/usamasadiq/bom-2305-pylint-amnesty
Applied pylint-amnesty
This commit is contained in:
@@ -1,2 +1,3 @@
|
||||
# lint-amnesty, pylint: disable=django-not-configured, missing-module-docstring
|
||||
from .formula import *
|
||||
from .symmath_check import *
|
||||
|
||||
@@ -21,7 +21,7 @@ import unicodedata
|
||||
#import subprocess
|
||||
from copy import deepcopy
|
||||
from functools import reduce
|
||||
from xml.sax.saxutils import unescape
|
||||
from xml.sax.saxutils import unescape # lint-amnesty, pylint: disable=unused-import
|
||||
|
||||
import six
|
||||
import sympy
|
||||
@@ -210,7 +210,7 @@ class formula(object):
|
||||
|
||||
for k in xml:
|
||||
tag = gettag(k)
|
||||
if tag == 'mi' or tag == 'ci':
|
||||
if tag == 'mi' or tag == 'ci': # lint-amnesty, pylint: disable=consider-using-in
|
||||
usym = six.text_type(k.text)
|
||||
try:
|
||||
udata = unicodedata.name(usym)
|
||||
@@ -227,7 +227,7 @@ class formula(object):
|
||||
self.fix_greek_in_mathml(k)
|
||||
return xml
|
||||
|
||||
def preprocess_pmathml(self, xml):
|
||||
def preprocess_pmathml(self, xml): # lint-amnesty, pylint: disable=too-many-statements
|
||||
r"""
|
||||
Pre-process presentation MathML from ASCIIMathML to make it more
|
||||
acceptable for SnuggleTeX, and also to accomodate some sympy
|
||||
@@ -420,7 +420,7 @@ class formula(object):
|
||||
self.xml = xml # pylint: disable=attribute-defined-outside-init
|
||||
return self.xml
|
||||
|
||||
def get_content_mathml(self):
|
||||
def get_content_mathml(self): # lint-amnesty, pylint: disable=missing-function-docstring
|
||||
if self.the_cmathml:
|
||||
return self.the_cmathml
|
||||
|
||||
@@ -436,7 +436,7 @@ class formula(object):
|
||||
|
||||
cmathml = property(get_content_mathml, None, None, 'content MathML representation')
|
||||
|
||||
def make_sympy(self, xml=None):
|
||||
def make_sympy(self, xml=None): # lint-amnesty, pylint: disable=too-many-statements
|
||||
"""
|
||||
Return sympy expression for the math formula.
|
||||
The math formula is converted to Content MathML then that is parsed.
|
||||
@@ -457,11 +457,11 @@ class formula(object):
|
||||
cmml = self.cmathml
|
||||
xml = etree.fromstring(str(cmml))
|
||||
except Exception as err:
|
||||
if 'conversion from Presentation MathML to Content MathML was not successful' in cmml:
|
||||
if 'conversion from Presentation MathML to Content MathML was not successful' in cmml: # lint-amnesty, pylint: disable=unsupported-membership-test
|
||||
msg = "Illegal math expression"
|
||||
else:
|
||||
msg = 'Err %s while converting cmathml to xml; cmml=%s' % (err, cmml)
|
||||
raise Exception(msg)
|
||||
raise Exception(msg) # lint-amnesty, pylint: disable=raise-missing-from
|
||||
xml = self.fix_greek_in_mathml(xml)
|
||||
self.the_sympy = self.make_sympy(xml[0])
|
||||
else:
|
||||
@@ -482,14 +482,14 @@ class formula(object):
|
||||
def op_minus(*args):
|
||||
if len(args) == 1:
|
||||
return -args[0]
|
||||
if not len(args) == 2:
|
||||
if not len(args) == 2: # lint-amnesty, pylint: disable=unneeded-not
|
||||
raise Exception('minus given wrong number of arguments!')
|
||||
#return sympy.Add(args[0],-args[1])
|
||||
return args[0] - args[1]
|
||||
|
||||
opdict = {
|
||||
'plus': op_plus,
|
||||
'divide': operator.div,
|
||||
'divide': operator.div, # lint-amnesty, pylint: disable=no-member
|
||||
'times': op_times,
|
||||
'minus': op_minus,
|
||||
'root': sympy.sqrt,
|
||||
@@ -546,7 +546,7 @@ class formula(object):
|
||||
except Exception as err:
|
||||
self.args = args # pylint: disable=attribute-defined-outside-init
|
||||
self.op = op # pylint: disable=attribute-defined-outside-init, invalid-name
|
||||
raise Exception('[formula] error=%s failed to apply %s to args=%s' % (err, opstr, args))
|
||||
raise Exception('[formula] error=%s failed to apply %s to args=%s' % (err, opstr, args)) # lint-amnesty, pylint: disable=raise-missing-from
|
||||
return res
|
||||
else:
|
||||
raise Exception('[formula]: unknown operator tag %s' % (opstr))
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/python # lint-amnesty, pylint: disable=missing-module-docstring
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# File: symmath_check.py
|
||||
@@ -16,7 +16,7 @@ from markupsafe import escape
|
||||
|
||||
from openedx.core.djangolib.markup import HTML
|
||||
|
||||
from .formula import *
|
||||
from .formula import * # lint-amnesty, pylint: disable=wildcard-import
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@@ -26,7 +26,7 @@ log = logging.getLogger(__name__)
|
||||
# This is one of the main entry points to call.
|
||||
|
||||
|
||||
def symmath_check_simple(expect, ans, adict={}, symtab=None, extra_options=None):
|
||||
def symmath_check_simple(expect, ans, adict={}, symtab=None, extra_options=None): # lint-amnesty, pylint: disable=dangerous-default-value, unused-argument
|
||||
"""
|
||||
Check a symbolic mathematical expression using sympy.
|
||||
The input is an ascii string (not MathML) converted to math using sympy.sympify.
|
||||
@@ -51,7 +51,7 @@ def symmath_check_simple(expect, ans, adict={}, symtab=None, extra_options=None)
|
||||
abcsym=options['__ABC__'],
|
||||
symtab=symtab,
|
||||
)
|
||||
except Exception as err:
|
||||
except Exception as err: # lint-amnesty, pylint: disable=broad-except
|
||||
return {'ok': False,
|
||||
'msg': HTML('Error {err}<br/>Failed in evaluating check({expect},{ans})').format(
|
||||
err=err, expect=expect, ans=ans
|
||||
@@ -62,7 +62,7 @@ def symmath_check_simple(expect, ans, adict={}, symtab=None, extra_options=None)
|
||||
# pretty generic checking function
|
||||
|
||||
|
||||
def check(expect, given, numerical=False, matrix=False, normphase=False, abcsym=False, do_qubit=True, symtab=None, dosimplify=False):
|
||||
def check(expect, given, numerical=False, matrix=False, normphase=False, abcsym=False, do_qubit=True, symtab=None, dosimplify=False): # lint-amnesty, pylint: disable=line-too-long
|
||||
"""
|
||||
Returns dict with
|
||||
|
||||
@@ -93,19 +93,19 @@ def check(expect, given, numerical=False, matrix=False, normphase=False, abcsym=
|
||||
threshold = float(st)
|
||||
numerical = True
|
||||
|
||||
if str(given) == '' and not str(expect) == '':
|
||||
if str(given) == '' and not str(expect) == '': # lint-amnesty, pylint: disable=unneeded-not
|
||||
return {'ok': False, 'msg': ''}
|
||||
|
||||
try:
|
||||
xgiven = my_sympify(given, normphase, matrix, do_qubit=do_qubit, abcsym=abcsym, symtab=symtab)
|
||||
except Exception as err:
|
||||
except Exception as err: # lint-amnesty, pylint: disable=broad-except
|
||||
return {'ok': False, 'msg': HTML('Error {err}<br/> in evaluating your expression "{given}"').format(
|
||||
err=err, given=given
|
||||
)}
|
||||
|
||||
try:
|
||||
xexpect = my_sympify(expect, normphase, matrix, do_qubit=do_qubit, abcsym=abcsym, symtab=symtab)
|
||||
except Exception as err:
|
||||
except Exception as err: # lint-amnesty, pylint: disable=broad-except
|
||||
return {'ok': False, 'msg': HTML('Error {err}<br/> in evaluating OUR expression "{expect}"').format(
|
||||
err=err, expect=expect
|
||||
)}
|
||||
@@ -113,12 +113,12 @@ def check(expect, given, numerical=False, matrix=False, normphase=False, abcsym=
|
||||
if 'autonorm' in flags: # normalize trace of matrices
|
||||
try:
|
||||
xgiven /= xgiven.trace()
|
||||
except Exception as err:
|
||||
except Exception as err: # lint-amnesty, pylint: disable=broad-except
|
||||
return {'ok': False, 'msg': HTML('Error {err}<br/> in normalizing trace of your expression {xgiven}').
|
||||
format(err=err, xgiven=to_latex(xgiven))}
|
||||
try:
|
||||
xexpect /= xexpect.trace()
|
||||
except Exception as err:
|
||||
except Exception as err: # lint-amnesty, pylint: disable=broad-except
|
||||
return {'ok': False, 'msg': HTML('Error {err}<br/> in normalizing trace of OUR expression {xexpect}').
|
||||
format(err=err, xexpect=to_latex(xexpect))}
|
||||
|
||||
@@ -172,7 +172,7 @@ def is_within_tolerance(expected, actual, tolerance):
|
||||
# This is one of the main entry points to call.
|
||||
|
||||
|
||||
def symmath_check(expect, ans, dynamath=None, options=None, debug=None, xml=None):
|
||||
def symmath_check(expect, ans, dynamath=None, options=None, debug=None, xml=None): # lint-amnesty, pylint: disable=too-many-statements
|
||||
"""
|
||||
Check a symbolic mathematical expression using sympy.
|
||||
The input may be presentation MathML. Uses formula.
|
||||
@@ -220,7 +220,7 @@ def symmath_check(expect, ans, dynamath=None, options=None, debug=None, xml=None
|
||||
# parse expected answer
|
||||
try:
|
||||
fexpect = my_sympify(str(expect), matrix=do_matrix, do_qubit=do_qubit)
|
||||
except Exception as err:
|
||||
except Exception as err: # lint-amnesty, pylint: disable=broad-except
|
||||
msg += HTML('<p>Error {err} in parsing OUR expected answer "{expect}"</p>').format(err=err, expect=expect)
|
||||
return {'ok': False, 'msg': make_error_message(msg)}
|
||||
|
||||
@@ -228,7 +228,7 @@ def symmath_check(expect, ans, dynamath=None, options=None, debug=None, xml=None
|
||||
# if expected answer is a number, try parsing provided answer as a number also
|
||||
try:
|
||||
fans = my_sympify(str(ans), matrix=do_matrix, do_qubit=do_qubit)
|
||||
except Exception as err:
|
||||
except Exception as err: # lint-amnesty, pylint: disable=broad-except
|
||||
fans = None
|
||||
|
||||
# do a numerical comparison if both expected and answer are numbers
|
||||
@@ -256,7 +256,7 @@ def symmath_check(expect, ans, dynamath=None, options=None, debug=None, xml=None
|
||||
# convert mathml answer to formula
|
||||
try:
|
||||
mmlans = dynamath[0] if dynamath else None
|
||||
except Exception as err:
|
||||
except Exception as err: # lint-amnesty, pylint: disable=broad-except
|
||||
mmlans = None
|
||||
if not mmlans:
|
||||
return {'ok': False, 'msg': '[symmath_check] failed to get MathML for input; dynamath=%s' % dynamath}
|
||||
@@ -268,7 +268,7 @@ def symmath_check(expect, ans, dynamath=None, options=None, debug=None, xml=None
|
||||
try:
|
||||
fsym = f.sympy
|
||||
msg += HTML('<p>You entered: {sympy}</p>').format(sympy=to_latex(f.sympy))
|
||||
except Exception as err:
|
||||
except Exception as err: # lint-amnesty, pylint: disable=broad-except
|
||||
log.exception("Error evaluating expression '%s' as a valid equation", ans)
|
||||
msg += HTML("<p>Error in evaluating your expression '{ans}' as a valid equation</p>").format(ans=ans)
|
||||
if "Illegal math" in str(err):
|
||||
@@ -309,7 +309,7 @@ def symmath_check(expect, ans, dynamath=None, options=None, debug=None, xml=None
|
||||
except sympy.ShapeError:
|
||||
msg += HTML("<p>Error - your input vector or matrix has the wrong dimensions")
|
||||
return {'ok': False, 'msg': make_error_message(msg)}
|
||||
except Exception as err:
|
||||
except Exception as err: # lint-amnesty, pylint: disable=broad-except
|
||||
msg += HTML("<p>Error %s in comparing expected (a list) and your answer</p>").format(escape(str(err)))
|
||||
if DEBUG:
|
||||
msg += HTML("<p/><pre>{format_exc}</pre>").format(format_exc=traceback.format_exc())
|
||||
@@ -320,7 +320,7 @@ def symmath_check(expect, ans, dynamath=None, options=None, debug=None, xml=None
|
||||
#fexpect = fexpect.simplify()
|
||||
try:
|
||||
diff = (fexpect - fsym)
|
||||
except Exception as err:
|
||||
except Exception as err: # lint-amnesty, pylint: disable=broad-except
|
||||
diff = None
|
||||
|
||||
if DEBUG:
|
||||
|
||||
@@ -16,13 +16,13 @@ def stripXML(xml):
|
||||
return xml
|
||||
|
||||
|
||||
class FormulaTest(unittest.TestCase):
|
||||
class FormulaTest(unittest.TestCase): # lint-amnesty, pylint: disable=missing-class-docstring
|
||||
# for readability later
|
||||
mathml_start = '<math xmlns="http://www.w3.org/1998/Math/MathML"><mstyle displaystyle="true">'
|
||||
mathml_end = '</mstyle></math>'
|
||||
|
||||
def setUp(self):
|
||||
super(FormulaTest, self).setUp()
|
||||
super(FormulaTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
self.formulaInstance = formula('')
|
||||
|
||||
def test_replace_mathvariants(self):
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
|
||||
# lint-amnesty, pylint: disable=missing-module-docstring
|
||||
from unittest import TestCase
|
||||
|
||||
from six.moves import range
|
||||
@@ -6,9 +6,9 @@ from six.moves import range
|
||||
from .symmath_check import symmath_check
|
||||
|
||||
|
||||
class SymmathCheckTest(TestCase):
|
||||
class SymmathCheckTest(TestCase): # lint-amnesty, pylint: disable=missing-class-docstring
|
||||
def test_symmath_check_integers(self):
|
||||
number_list = [i for i in range(-100, 100)]
|
||||
number_list = [i for i in range(-100, 100)] # lint-amnesty, pylint: disable=unnecessary-comprehension
|
||||
self._symmath_check_numbers(number_list)
|
||||
|
||||
def test_symmath_check_floats(self):
|
||||
@@ -73,7 +73,7 @@ class SymmathCheckTest(TestCase):
|
||||
self.assertTrue('ok' in result and not result['ok'])
|
||||
self.assertNotIn('fail', result['msg'])
|
||||
|
||||
def _symmath_check_numbers(self, number_list):
|
||||
def _symmath_check_numbers(self, number_list): # lint-amnesty, pylint: disable=missing-function-docstring
|
||||
|
||||
for n in number_list:
|
||||
|
||||
|
||||
@@ -333,7 +333,7 @@ class AssignmentFormatGrader(CourseGrader):
|
||||
min_count = 2 would produce the labels "Assignment 3", "Assignment 4"
|
||||
|
||||
"""
|
||||
def __init__(
|
||||
def __init__( # lint-amnesty, pylint: disable=super-init-not-called
|
||||
self,
|
||||
type, # pylint: disable=redefined-builtin
|
||||
min_count,
|
||||
|
||||
Reference in New Issue
Block a user