Commit 8a1877f0 by Ned Batchelder

Merge pull request #7436 from edx/ned/upgrade-pylint

Upgrade pylint
parents c01ab4a8 5a414914
...@@ -1560,7 +1560,7 @@ class AnnotationInput(InputTypeBase): ...@@ -1560,7 +1560,7 @@ class AnnotationInput(InputTypeBase):
def _unpack(self, json_value): def _unpack(self, json_value):
""" Unpacks the json input state into a dict. """ """ Unpacks the json input state into a dict. """
d = json.loads(json_value) d = json.loads(json_value)
if type(d) != dict: if not isinstance(d, dict):
d = {} d = {}
comment_value = d.get('comment', '') comment_value = d.get('comment', '')
......
...@@ -2505,7 +2505,7 @@ class FormulaResponse(LoncapaResponse): ...@@ -2505,7 +2505,7 @@ class FormulaResponse(LoncapaResponse):
converted to float. Used so we can safely use Python contexts. converted to float. Used so we can safely use Python contexts.
""" """
inp_d = dict([(k, numpy.complex(inp_d[k])) inp_d = dict([(k, numpy.complex(inp_d[k]))
for k in inp_d if type(k) == str and for k in inp_d if isinstance(k, str) and
k.isalnum() and k.isalnum() and
isinstance(inp_d[k], numbers.Number)]) isinstance(inp_d[k], numbers.Number)])
return inp_d return inp_d
...@@ -2683,7 +2683,7 @@ class ImageResponse(LoncapaResponse): ...@@ -2683,7 +2683,7 @@ class ImageResponse(LoncapaResponse):
if correct_map[aid]['correctness'] != 'correct' and regions[aid]: if correct_map[aid]['correctness'] != 'correct' and regions[aid]:
parsed_region = json.loads(regions[aid]) parsed_region = json.loads(regions[aid])
if parsed_region: if parsed_region:
if type(parsed_region[0][0]) != list: if not isinstance(parsed_region[0][0], list):
# we have [[1,2],[3,4],[5,6]] - single region # we have [[1,2],[3,4],[5,6]] - single region
# instead of [[[1,2],[3,4],[5,6], [[1,2],[3,4],[5,6]]] # instead of [[[1,2],[3,4],[5,6], [[1,2],[3,4],[5,6]]]
# or [[[1,2],[3,4],[5,6]]] - multiple regions syntax # or [[[1,2],[3,4],[5,6]]] - multiple regions syntax
...@@ -2833,7 +2833,7 @@ class AnnotationResponse(LoncapaResponse): ...@@ -2833,7 +2833,7 @@ class AnnotationResponse(LoncapaResponse):
def _unpack(self, json_value): def _unpack(self, json_value):
"""Unpacks a student response value submitted as JSON.""" """Unpacks a student response value submitted as JSON."""
json_d = json.loads(json_value) json_d = json.loads(json_value)
if type(json_d) != dict: if not isinstance(json_d, dict):
json_d = {} json_d = {}
comment_value = json_d.get('comment', '') comment_value = json_d.get('comment', '')
......
...@@ -823,7 +823,7 @@ class ChoiceTextResponseXMLFactory(ResponseXMLFactory): ...@@ -823,7 +823,7 @@ class ChoiceTextResponseXMLFactory(ResponseXMLFactory):
choice_inputs = [] choice_inputs = []
# Ensure that the first element of choices is an ordered # Ensure that the first element of choices is an ordered
# collection. It will start as a list, a tuple, or not a Container. # collection. It will start as a list, a tuple, or not a Container.
if type(choices[0]) not in [list, tuple]: if not isinstance(choices[0], (list, tuple)):
choices = [choices] choices = [choices]
for choice in choices: for choice in choices:
...@@ -838,7 +838,7 @@ class ChoiceTextResponseXMLFactory(ResponseXMLFactory): ...@@ -838,7 +838,7 @@ class ChoiceTextResponseXMLFactory(ResponseXMLFactory):
# Make sure that `answers` is an ordered collection for # Make sure that `answers` is an ordered collection for
# convenience. # convenience.
if type(answers) not in [list, tuple]: if not isinstance(answers, (list, tuple)):
answers = [answers] answers = [answers]
numtolerance_inputs = [ numtolerance_inputs = [
......
...@@ -91,7 +91,7 @@ def _clean_parse_tree(tree): ...@@ -91,7 +91,7 @@ def _clean_parse_tree(tree):
'paren_group_square': lambda x: nltk.tree.Tree(x.node, x[1]), 'paren_group_square': lambda x: nltk.tree.Tree(x.node, x[1]),
'paren_group_round': lambda x: nltk.tree.Tree(x.node, x[1])} 'paren_group_round': lambda x: nltk.tree.Tree(x.node, x[1])}
if type(tree) == str: if isinstance(tree, str):
return tree return tree
old_node = None old_node = None
...@@ -124,7 +124,7 @@ def _merge_children(tree, tags): ...@@ -124,7 +124,7 @@ def _merge_children(tree, tags):
# Haven't grokked the code to tell if this is indeed the right thing to do. # Haven't grokked the code to tell if this is indeed the right thing to do.
raise ParseException("Shouldn't have empty trees") raise ParseException("Shouldn't have empty trees")
if type(tree) == str: if isinstance(tree, str):
return tree return tree
merged_children = [] merged_children = []
...@@ -134,7 +134,7 @@ def _merge_children(tree, tags): ...@@ -134,7 +134,7 @@ def _merge_children(tree, tags):
while not done: while not done:
done = True done = True
for child in tree: for child in tree:
if type(child) == nltk.tree.Tree and child.node == tree.node and tree.node in tags: if isinstance(child, nltk.tree.Tree) and child.node == tree.node and tree.node in tags:
merged_children = merged_children + list(child) merged_children = merged_children + list(child)
done = False done = False
else: else:
...@@ -182,7 +182,7 @@ def _render_to_html(tree): ...@@ -182,7 +182,7 @@ def _render_to_html(tree):
'paren_group_round': round_brackets, 'paren_group_round': round_brackets,
'paren_group_square': square_brackets} 'paren_group_square': square_brackets}
if type(tree) == str: if isinstance(tree, str):
return tree return tree
else: else:
children = "".join(map(_render_to_html, tree)) children = "".join(map(_render_to_html, tree))
......
...@@ -96,7 +96,7 @@ def my_evalf(expr, chop=False): ...@@ -96,7 +96,7 @@ def my_evalf(expr, chop=False):
Enhanced sympy evalf to handle lists of expressions Enhanced sympy evalf to handle lists of expressions
and catch eval failures without dropping out. and catch eval failures without dropping out.
""" """
if type(expr) == list: if isinstance(expr, list):
try: try:
return [x.evalf(chop=chop) for x in expr] return [x.evalf(chop=chop) for x in expr]
except: except:
...@@ -140,7 +140,7 @@ def my_sympify(expr, normphase=False, matrix=False, abcsym=False, do_qubit=False ...@@ -140,7 +140,7 @@ def my_sympify(expr, normphase=False, matrix=False, abcsym=False, do_qubit=False
sexpr = sympify(expr, locals=varset) sexpr = sympify(expr, locals=varset)
if normphase: # remove overall phase if sexpr is a list if normphase: # remove overall phase if sexpr is a list
if type(sexpr) == list: if isinstance(sexpr, list):
if sexpr[0].is_number: if sexpr[0].is_number:
ophase = sympy.sympify('exp(-I*arg(%s))' % sexpr[0]) ophase = sympy.sympify('exp(-I*arg(%s))' % sexpr[0])
sexpr = [sympy.Mul(x, ophase) for x in sexpr] sexpr = [sympy.Mul(x, ophase) for x in sexpr]
...@@ -150,10 +150,10 @@ def my_sympify(expr, normphase=False, matrix=False, abcsym=False, do_qubit=False ...@@ -150,10 +150,10 @@ def my_sympify(expr, normphase=False, matrix=False, abcsym=False, do_qubit=False
Convert a list, or list of lists to a matrix. Convert a list, or list of lists to a matrix.
""" """
# if expr is a list of lists, and is rectangular, then return Matrix(expr) # if expr is a list of lists, and is rectangular, then return Matrix(expr)
if not type(expr) == list: if not isinstance(expr, list):
return expr return expr
for row in expr: for row in expr:
if (not type(row) == list): if not isinstance(row, list):
return expr return expr
rdim = len(expr[0]) rdim = len(expr[0])
for row in expr: for row in expr:
...@@ -230,7 +230,7 @@ class formula(object): ...@@ -230,7 +230,7 @@ class formula(object):
it, if possible... it, if possible...
""" """
if type(xml) == str or type(xml) == unicode: if isinstance(xml, (str, unicode)):
xml = etree.fromstring(xml) # TODO: wrap in try xml = etree.fromstring(xml) # TODO: wrap in try
xml = self.fix_greek_in_mathml(xml) # convert greek utf letters to greek spelled out in ascii xml = self.fix_greek_in_mathml(xml) # convert greek utf letters to greek spelled out in ascii
......
...@@ -287,7 +287,7 @@ def symmath_check(expect, ans, dynamath=None, options=None, debug=None, xml=None ...@@ -287,7 +287,7 @@ def symmath_check(expect, ans, dynamath=None, options=None, debug=None, xml=None
if fexpect == fsym: if fexpect == fsym:
return {'ok': True, 'msg': msg} return {'ok': True, 'msg': msg}
if type(fexpect) == list: if isinstance(fexpect, list):
try: try:
xgiven = my_evalf(fsym, chop=True) xgiven = my_evalf(fsym, chop=True)
dm = my_evalf(sympy.Matrix(fexpect) - sympy.Matrix(xgiven), chop=True) dm = my_evalf(sympy.Matrix(fexpect) - sympy.Matrix(xgiven), chop=True)
......
...@@ -321,8 +321,8 @@ class LTI20ModuleMixin(object): ...@@ -321,8 +321,8 @@ class LTI20ModuleMixin(object):
# the standard supports a list of objects, who knows why. It must contain at least 1 element, and the # the standard supports a list of objects, who knows why. It must contain at least 1 element, and the
# first element must be a dict # first element must be a dict
if type(json_obj) != dict: if not isinstance(json_obj, dict):
if type(json_obj) == list and len(json_obj) >= 1 and type(json_obj[0]) == dict: if isinstance(json_obj, list) and len(json_obj) >= 1 and isinstance(json_obj[0], dict):
json_obj = json_obj[0] json_obj = json_obj[0]
else: else:
msg = ("Supplied JSON string is a list that does not contain an object as the first element. {}" msg = ("Supplied JSON string is a list that does not contain an object as the first element. {}"
......
...@@ -126,7 +126,7 @@ class CourseTab(object): ...@@ -126,7 +126,7 @@ class CourseTab(object):
was implemented). was implemented).
""" """
if type(other) is dict and not self.validate(other, raise_error=False): if isinstance(other, dict) and not self.validate(other, raise_error=False):
# 'other' is a dict-type tab and did not validate # 'other' is a dict-type tab and did not validate
return False return False
......
...@@ -51,9 +51,9 @@ class FolditTestCase(TestCase): ...@@ -51,9 +51,9 @@ class FolditTestCase(TestCase):
Given lists of puzzle_ids and best_scores (must have same length), make a Given lists of puzzle_ids and best_scores (must have same length), make a
SetPlayerPuzzleScores request and return the response. SetPlayerPuzzleScores request and return the response.
""" """
if not(type(best_scores) == list): if not isinstance(best_scores, list):
best_scores = [best_scores] best_scores = [best_scores]
if not(type(puzzle_ids) == list): if not isinstance(puzzle_ids, list):
puzzle_ids = [puzzle_ids] puzzle_ids = [puzzle_ids]
user = self.user if not user else user user = self.user if not user else user
......
...@@ -139,7 +139,7 @@ def manage_modulestores(request, reload_dir=None, commit_id=None): ...@@ -139,7 +139,7 @@ def manage_modulestores(request, reload_dir=None, commit_id=None):
for field in dumpfields: for field in dumpfields:
data = getattr(course, field, None) data = getattr(course, field, None)
html += '<h3>%s</h3>' % field html += '<h3>%s</h3>' % field
if type(data) == dict: if isinstance(data, dict):
html += '<ul>' html += '<ul>'
for k, v in data.items(): for k, v in data.items():
html += '<li>%s:%s</li>' % (escape(k), escape(v)) html += '<li>%s:%s</li>' % (escape(k), escape(v))
......
...@@ -37,7 +37,7 @@ class CoursesWithFriends(generics.ListAPIView): ...@@ -37,7 +37,7 @@ class CoursesWithFriends(generics.ListAPIView):
# Get friends from Facebook # Get friends from Facebook
result = get_friends_from_facebook(serializer) result = get_friends_from_facebook(serializer)
if type(result) != list: if not isinstance(result, list):
return result return result
friends_that_are_edx_users = get_linked_edx_accounts(result) friends_that_are_edx_users = get_linked_edx_accounts(result)
......
...@@ -46,7 +46,7 @@ class FriendsInCourse(generics.ListAPIView): ...@@ -46,7 +46,7 @@ class FriendsInCourse(generics.ListAPIView):
# Get all the user's FB friends # Get all the user's FB friends
result = get_friends_from_facebook(serializer) result = get_friends_from_facebook(serializer)
if type(result) != list: if not isinstance(result, list):
return result return result
def is_member(friend, course_key): def is_member(friend, course_key):
......
...@@ -30,7 +30,7 @@ class Note(models.Model): ...@@ -30,7 +30,7 @@ class Note(models.Model):
raise ValidationError('Note must have a body.') raise ValidationError('Note must have a body.')
body = json.loads(json_body) body = json.loads(json_body)
if not type(body) is dict: if not isinstance(body, dict):
raise ValidationError('Note body must be a dictionary.') raise ValidationError('Note body must be a dictionary.')
# NOTE: all three of these fields should be considered user input # NOTE: all three of these fields should be considered user input
......
...@@ -125,6 +125,7 @@ django_debug_toolbar==1.2.2 ...@@ -125,6 +125,7 @@ django_debug_toolbar==1.2.2
django-debug-toolbar-mongo django-debug-toolbar-mongo
# Used for testing # Used for testing
astroid==1.3.4
chrono==1.0.2 chrono==1.0.2
coverage==3.7 coverage==3.7
ddt==0.8.0 ddt==0.8.0
...@@ -141,7 +142,7 @@ nose-ignore-docstring ...@@ -141,7 +142,7 @@ nose-ignore-docstring
nosexcover==1.0.7 nosexcover==1.0.7
pep8==1.5.7 pep8==1.5.7
PyContracts==1.7.1 PyContracts==1.7.1
pylint==1.4.1 pylint==1.4.2
python-subunit==0.0.16 python-subunit==0.0.16
radon==1.2 radon==1.2
rednose==0.3 rednose==0.3
......
...@@ -61,7 +61,7 @@ git clean -qxfd ...@@ -61,7 +61,7 @@ git clean -qxfd
source scripts/jenkins-common.sh source scripts/jenkins-common.sh
# Violations thresholds for failing the build # Violations thresholds for failing the build
PYLINT_THRESHOLD=5800 PYLINT_THRESHOLD=5500
# If the environment variable 'SHARD' is not set, default to 'all'. # If the environment variable 'SHARD' is not set, default to 'all'.
# This could happen if you are trying to use this script from # This could happen if you are trying to use this script from
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment