From b574dcb8e8b339f9b19a31dfa9ab11dac6046c49 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Fri, 1 Jun 2012 12:18:43 -0400 Subject: [PATCH] Check for None with is rather than == --- djangoapps/courseware/capa/capa_problem.py | 2 +- djangoapps/courseware/capa/inputtypes.py | 2 +- djangoapps/courseware/capa/responsetypes.py | 12 ++++++------ djangoapps/courseware/content_parser.py | 2 +- djangoapps/courseware/grades.py | 2 +- djangoapps/courseware/module_render.py | 2 +- djangoapps/courseware/modules/capa_module.py | 4 ++-- djangoapps/courseware/modules/seq_module.py | 4 ++-- djangoapps/courseware/modules/video_module.py | 2 +- djangoapps/courseware/views.py | 4 ++-- djangoapps/simplewiki/views.py | 2 +- templates/video.html | 2 +- 12 files changed, 20 insertions(+), 20 deletions(-) diff --git a/djangoapps/courseware/capa/capa_problem.py b/djangoapps/courseware/capa/capa_problem.py index 565e82a577..4c74d5315f 100644 --- a/djangoapps/courseware/capa/capa_problem.py +++ b/djangoapps/courseware/capa/capa_problem.py @@ -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: diff --git a/djangoapps/courseware/capa/inputtypes.py b/djangoapps/courseware/capa/inputtypes.py index d50e41a5a3..e535ec400e 100644 --- a/djangoapps/courseware/capa/inputtypes.py +++ b/djangoapps/courseware/capa/inputtypes.py @@ -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 diff --git a/djangoapps/courseware/capa/responsetypes.py b/djangoapps/courseware/capa/responsetypes.py index 3159b70d5c..d35d526b30 100644 --- a/djangoapps/courseware/capa/responsetypes.py +++ b/djangoapps/courseware/capa/responsetypes.py @@ -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 diff --git a/djangoapps/courseware/content_parser.py b/djangoapps/courseware/content_parser.py index 9d8811307f..06c07bff64 100644 --- a/djangoapps/courseware/content_parser.py +++ b/djangoapps/courseware/content_parser.py @@ -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) diff --git a/djangoapps/courseware/grades.py b/djangoapps/courseware/grades.py index 2013dc28b5..ca4d00a0db 100644 --- a/djangoapps/courseware/grades.py +++ b/djangoapps/courseware/grades.py @@ -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 diff --git a/djangoapps/courseware/module_render.py b/djangoapps/courseware/module_render.py index 510d26033c..ba550fe935 100644 --- a/djangoapps/courseware/module_render.py +++ b/djangoapps/courseware/module_render.py @@ -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 diff --git a/djangoapps/courseware/modules/capa_module.py b/djangoapps/courseware/modules/capa_module.py index b54b028c11..25874c32b5 100644 --- a/djangoapps/courseware/modules/capa_module.py +++ b/djangoapps/courseware/modules/capa_module.py @@ -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 diff --git a/djangoapps/courseware/modules/seq_module.py b/djangoapps/courseware/modules/seq_module.py index 063c37e5b3..deec191173 100644 --- a/djangoapps/courseware/modules/seq_module.py +++ b/djangoapps/courseware/modules/seq_module.py @@ -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']) diff --git a/djangoapps/courseware/modules/video_module.py b/djangoapps/courseware/modules/video_module.py index 80a1ce2f80..41c76fc717 100644 --- a/djangoapps/courseware/modules/video_module.py +++ b/djangoapps/courseware/modules/video_module.py @@ -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'])) diff --git a/djangoapps/courseware/views.py b/djangoapps/courseware/views.py index 8c61e1c121..0a4fc53fff 100644 --- a/djangoapps/courseware/views.py +++ b/djangoapps/courseware/views.py @@ -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) diff --git a/djangoapps/simplewiki/views.py b/djangoapps/simplewiki/views.py index 34a81e6b57..167ce27d95 100644 --- a/djangoapps/simplewiki/views.py +++ b/djangoapps/simplewiki/views.py @@ -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): diff --git a/templates/video.html b/templates/video.html index 54d6f8fa37..f49b5b56c2 100644 --- a/templates/video.html +++ b/templates/video.html @@ -1,4 +1,4 @@ -% if name is not UNDEFINED and name != None: +% if name is not UNDEFINED and name is not None:

${name}

% endif