Python Nonetype check on custom exception handling not working [duplicate]

I have been running this simple code for exception handling. It runs correctly in every scenario except when there need to check for Nonetype. I have used every line of code but nothing worked for me. Below I just kept simple, can you please help me here why it is not going inside if condition.? [updated] : Placed more print statements to give more insight on the issue. It is being called like "raise CustomExcpetion(excep=e)" in django

class CustomExcpetion(PermissionDenied):
    def __init__(self, excep, status_code=status.HTTP_400_BAD_REQUEST):
        message={"message": "error observed"}
        print ("Inside custom exception")
        print (excep)
        excepType = type(excep)
        print ("exception type found : ")
        print(excepType)
        
        if excep is None:
             print ("none exception found")
             self.detail = message
        print ("none exception NOT found")

enter image description here

Back to Top