Commit b574dcb8 by Calen Pennington

Check for None with is rather than ==

parent 71e25d9b
......@@ -91,7 +91,7 @@ class LoncapaProblem(object):
self.problem_id = id
self.system = system
if seed != None:
if seed is not None:
self.seed = seed
if state:
......
......@@ -133,7 +133,7 @@ class SimpleInput():# XModule
def register_render_function(fn, names=None, cls=SimpleInput):
if names == None:
if names is None:
SimpleInput.xml_tags[fn.__name__] = fn
else:
raise NotImplementedError
......
......@@ -109,7 +109,7 @@ class MultipleChoiceResponse(GenericResponse):
if rtype not in ["MultipleChoice"]:
response.set("type", "MultipleChoice") # force choicegroup to be MultipleChoice if not valid
for choice in list(response):
if choice.get("name") == None:
if choice.get("name") is None:
choice.set("name", "choice_"+str(i))
i+=1
else:
......@@ -121,7 +121,7 @@ class TrueFalseResponse(MultipleChoiceResponse):
for response in self.xml.xpath("choicegroup"):
response.set("type", "TrueFalse")
for choice in list(response):
if choice.get("name") == None:
if choice.get("name") is None:
choice.set("name", "choice_"+str(i))
i+=1
else:
......@@ -292,7 +292,7 @@ def sympy_check2():
self.code = ''
else:
answer_src = answer.get('src')
if answer_src != None:
if answer_src is not None:
self.code = open(settings.DATA_DIR+'src/'+answer_src).read()
else:
self.code = answer.text
......@@ -418,7 +418,7 @@ class ExternalResponse(GenericResponse):
id=xml.get('id'))[0]
answer_src = answer.get('src')
if answer_src != None:
if answer_src is not None:
self.code = open(settings.DATA_DIR+'src/'+answer_src).read()
else:
self.code = answer.text
......@@ -489,7 +489,7 @@ class FormulaResponse(GenericResponse):
self.context = context
ts = xml.get('type')
if ts == None:
if ts is None:
typeslist = []
else:
typeslist = ts.split(',')
......@@ -558,7 +558,7 @@ class SchematicResponse(GenericResponse):
answer = xml.xpath('//*[@id=$id]//answer',
id=xml.get('id'))[0]
answer_src = answer.get('src')
if answer_src != None:
if answer_src is not None:
self.code = self.system.filestore.open('src/'+answer_src).read() # Untested; never used
else:
self.code = answer.text
......
......@@ -126,7 +126,7 @@ def propogate_downward_tag(element, attribute_name, parent_attribute = None):
child (A) already has that attribute, A will keep the same attribute and
all of A's children will inherit A's attribute. This is a recursive call.'''
if (parent_attribute == None): #This is the entry call. Select all elements with this attribute
if (parent_attribute is None): #This is the entry call. Select all elements with this attribute
all_attributed_elements = element.xpath("//*[@" + attribute_name +"]")
for attributed_element in all_attributed_elements:
attribute_value = attributed_element.get(attribute_name)
......
......@@ -190,7 +190,7 @@ def get_score(user, problem, cache, coursename=None):
correct=float(response.grade)
# Grab max grade from cache, or if it doesn't exist, compute and save to DB
if id in cache and response.max_grade != None:
if id in cache and response.max_grade is not None:
total = response.max_grade
else:
## HACK 1: We shouldn't specifically reference capa_module
......
......@@ -75,7 +75,7 @@ def grade_histogram(module_id):
grades = list(cursor.fetchall())
grades.sort(key=lambda x:x[0]) # Probably not necessary
if (len(grades) == 1 and grades[0][0] == None):
if (len(grades) == 1 and grades[0][0] is None):
return []
return grades
......
......@@ -97,7 +97,7 @@ class Module(XModule):
reset_button = False
# We don't need a "save" button if infinite number of attempts and non-randomized
if self.max_attempts == None and self.rerandomize != "always":
if self.max_attempts is None and self.rerandomize != "always":
save_button = False
# Check if explanation is available, and if so, give a link
......@@ -222,7 +222,7 @@ class Module(XModule):
''' Is the student still allowed to submit answers? '''
if self.attempts == self.max_attempts:
return True
if self.close_date != None and datetime.datetime.utcnow() > self.close_date:
if self.close_date is not None and datetime.datetime.utcnow() > self.close_date:
return True
return False
......
......@@ -51,7 +51,7 @@ class Module(XModule):
## Returns a set of all types of all sub-children
child_classes = [set([i.tag for i in e.iter()]) for e in self.xmltree]
titles = ["\n".join([i.get("name").strip() for i in e.iter() if i.get("name") != None]) \
titles = ["\n".join([i.get("name").strip() for i in e.iter() if i.get("name") is not None]) \
for e in self.xmltree]
self.contents = [j(self.render_function(e)) for e in self.xmltree]
......@@ -91,7 +91,7 @@ class Module(XModule):
self.position = 1
if state != None:
if state is not None:
state = json.loads(state)
if 'position' in state: self.position = int(state['position'])
......
......@@ -47,7 +47,7 @@ class Module(XModule):
self.youtube = xmltree.get('youtube')
self.name = xmltree.get('name')
self.position = 0
if state != None:
if state is not None:
state = json.loads(state)
if 'position' in state:
self.position = int(float(state['position']))
......
......@@ -57,7 +57,7 @@ def profile(request, student_id = None):
''' User profile. Show username, location, etc, as well as grades .
We need to allow the user to change some of these settings .'''
if student_id == None:
if student_id is None:
student = request.user
else:
if 'course_admin' not in content_parser.user_groups(request.user):
......@@ -194,7 +194,7 @@ def index(request, course=None, chapter="Using the System", section="Hints"):
else:
module_wrapper = dom_module[0]
if module_wrapper == None:
if module_wrapper is None:
module = None
elif module_wrapper.get("src"):
module = content_parser.section_file(user=user, section=module_wrapper.get("src"), coursename=course)
......
......@@ -482,7 +482,7 @@ def check_permissions(request, article, check_read=False, check_write=False, che
locked_err = check_locked and article.locked
if revision == None:
if revision is None:
revision = article.current_revision
deleted_err = check_deleted and not (revision.deleted == 0)
if (request.user.is_superuser):
......
% if name is not UNDEFINED and name != None:
% if name is not UNDEFINED and name is not None:
<h1> ${name} </h1>
% endif
......
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