Comparison to singleton
False
should be expr is False
629 results = transcript.course_result.all()
630 total_cr = 0
631 for sheet in results:
632 if last_course_being_final and sheet.finalized == False:633 last_course_being_final = False
634 sum += sheet.gpa*sheet.course.credit_hour
635 count += 1
Comparison to singleton
None
should be expr is None
573 #grading_type = request.POST['Type']
574 scheme = 0
575 scsddc = request.POST['scsddc']
576 if scsddc == None or scsddc == "" or scsddc == "null":577 return JsonResponse({"Error": "Invalid scsddc"}, status=403)
578 csection = CourseSection.objects.get(scsddc=scsddc)
579 for student_info in csection.student_info.all():
Comparison to singleton
None
should be expr is None
529def marks_info(request):
530 scsddc = request.POST['scsddc']
531 print(scsddc)
532 if scsddc == None or scsddc == "" or scsddc == "null":533 return JsonResponse({"Failed": "Invalid Input Parameters"}, status=403)
534 print(scsddc)
535 marks = SectionMarks.objects.filter(scsddc=scsddc).values()
Comparison to singleton
None
should be expr is None
437 info = csection.student_info.get(student=student_info.student)
438
439 info.mark_sheet.Marks.add(new_a)
440 if info.mark_sheet.grand_total_marks == None:441 info.mark_sheet.grand_total_marks = 0.0
442 info.mark_sheet.grand_total_marks += float(section_marks.weightage)
443 info.mark_sheet.year = year
Comparison to singleton
None
should be expr is None
240 scsddc = request.POST['scsddc']
241 marks_type = request.POST['marks_type']
242 marks_data = json.loads(request.POST['marks_data'])
243 if marks_type == None or marks_type == "" or scsddc == None or scsddc == "" or marks_data == None or marks_data == "":244 return JsonResponse({"Failed": "Invalid Input Parameters"}, status=403)
245 else:
246 try:
Comparison to singleton
None
should be expr is None
240 scsddc = request.POST['scsddc']
241 marks_type = request.POST['marks_type']
242 marks_data = json.loads(request.POST['marks_data'])
243 if marks_type == None or marks_type == "" or scsddc == None or scsddc == "" or marks_data == None or marks_data == "":244 return JsonResponse({"Failed": "Invalid Input Parameters"}, status=403)
245 else:
246 try:
Comparison to singleton
None
should be expr is None
240 scsddc = request.POST['scsddc']
241 marks_type = request.POST['marks_type']
242 marks_data = json.loads(request.POST['marks_data'])
243 if marks_type == None or marks_type == "" or scsddc == None or scsddc == "" or marks_data == None or marks_data == "":244 return JsonResponse({"Failed": "Invalid Input Parameters"}, status=403)
245 else:
246 try:
Comparison to singleton
None
should be expr is None
149 def post(self, request):
150 marks_type = request.POST['marks_type']
151 scsddc = request.POST['scsddc']
152 if marks_type == None or marks_type == "" or scsddc == None or scsddc == "" or scsddc == "null":153 return JsonResponse({"Failure": "Parameters Are Not Valid"}, safe=False, status=403)
154 student_marks = StudentMarks.objects.filter(
155 marks_type=marks_type, scsddc=scsddc)
Comparison to singleton
None
should be expr is None
149 def post(self, request):
150 marks_type = request.POST['marks_type']
151 scsddc = request.POST['scsddc']
152 if marks_type == None or marks_type == "" or scsddc == None or scsddc == "" or scsddc == "null":153 return JsonResponse({"Failure": "Parameters Are Not Valid"}, safe=False, status=403)
154 student_marks = StudentMarks.objects.filter(
155 marks_type=marks_type, scsddc=scsddc)
Comparison to singleton
True
should be expr is True
166 if dep is None or deg is None:
167 return JsonResponse({'message': 'Invalid Student', 'condition': True}, status=401)
168
169 if(deg.registrations_open == True):170 return JsonResponse({'message': 'Regisrations are Active', 'condition': True}, status=200)
171 else:
172 return JsonResponse({'message': 'Regisrations are NOT Active', 'condition': False}, status=200)
Comparison to singleton
False
should be expr is False
236 if user is None:
237 return JsonResponse({'message': "Invalid Id Or Password", 'status': 'failure'}, status=403)
238
239 if user.is_student == False:240 return JsonResponse({'message': 'User is Not a Student',
241 'condtion': False, 'status': 'failure'}, status=401)
242
Comparison to singleton
True
should be expr is True
391 semester = Semester.objects.get(semester_code=request.POST['semester'])
392 challan, created = FeeChallan.objects.get_or_create(
393 student=student, semester=semester)
394 if created == True:395 transcript = Transcript.objects.get_or_create(
396 student=student, semester=Semester.objects.get(current_semester=True))[0]
397 challan.coActivity_charges = semester.co_circular_fee
Comparison to singleton
None
should be expr is None
484 def post(self, request):
485 section = request.POST['section']
486 code = request.POST['code']
487 if section == None or section == "" or section == "null" or code == None or code == "" or code == "null":488 return JsonResponse({"Failed": "Invalid Input Parameters"}, status=403)
489 else:
490 student = Student.objects.get(user=request.user)
Comparison to singleton
None
should be expr is None
484 def post(self, request):
485 section = request.POST['section']
486 code = request.POST['code']
487 if section == None or section == "" or section == "null" or code == None or code == "" or code == "null":488 return JsonResponse({"Failed": "Invalid Input Parameters"}, status=403)
489 else:
490 student = Student.objects.get(user=request.user)
Description
Comparisons to the singleton objects, like True
, False
, and None
, should be done with identity, not equality. Use is
or is not
.
Identity checks are faster than equality checks.
Also, the equality checks can result in unintended behaviour in some cases:
>>> 1 is True
False
>>> 1 == True
True
>>> 1.0 is True
False
>>> 1.0 == True
True
Bad practice
value = fx()
if value == True: # `==` can cause unintended behaviour
print(value)
if value != None:
print(value)
Recommended
value = fx()
if value is True: # `is` for Identity comparison
print(value)
if value is not None:
print(value)
Exceptions:
Equality comparisons might be required in some cases, especially in SQLAlchemy, SQLObject, ORMs, etc. In these cases, it is safe to ignore this issue.