Unorderable types in Python: NoneType() and int(). Using an interface to make this method
Question: I am in the finishing stages of finishing up a project that is due on July 6,
2015 to get all the errors fixed. I seem to have run across an error in which
I have no discern-able answer:

    
    
      File "Z:\Jordan White's Folder\Concepts of Programming CS 4150 Summer Semester 2015\Projects\cs4150pythonproject\BooleanExpressions.py", line 30, in evaluate
    value = self.expr1.evaluate() < self.expr2.evaluate()
      TypeError: unorderable types: NoneType() < int()
    

The line is pointing to line 30 in this code:

    
    
     '''
     Created on Jun 22, 2015
    
     @author: JordanWhite
     '''
    
     from RelationalOperators import RelationalOperator
     class BooleanExpression():
    
    def __init__(self, op, expr1, expr2):
        if expr1 == None or expr2 == None:
            raise Exception("null expression argument")
        self.op = op
        self.expr1 = expr1
        self.expr2 = expr2
    
    def evaluate(self):
        value = True
        int(0 if value is None else value)
        if self.op == RelationalOperator.EQ_OP:
            value = self.expr1.evaluate() == self.expr2.evaluate()
        elif self.op == RelationalOperator.NE_OP:
            value = self.expr1.evaluate() != self.expr2.evaluate()
        elif self.op == RelationalOperator.GE_OP:
            value = self.expr1.evaluate() >= self.expr2.evaluate()
        elif self.op == RelationalOperator.GT_OP:
            value = self.expr1.evaluate() > self.expr2.evaluate()
        elif self.op == RelationalOperator.LE_OP:
            value = self.expr1.evaluate() <= self.expr2.evaluate()
        elif self.op == RelationalOperator.LT_OP:
            value = self.expr1.evaluate() < self.expr2.evaluate()
        return value
    

The expr1 variable is somehow being registered as a NoneType, when it is meant
to be an int() variable. Expression is an interface, as shown here:

    
    
    '''
    Created on Jun 18, 2015
    
    @author: JordanWhite
    '''
    class Expression():
    
        def evaluate(self):
            pass
    

The goal is when the boolean expression is evaluated, it prints out in the
Parser as true, and when it's true, it fetches the value of x := 12 in the
Pascal program here:

    
    
    Program a ;
    
    begin
        x := 4 ;
        if < x 7 then
            x := 12 
        else
            x := 14 ;
        write ( x )
    end .
    

How on earth do I fix something like this, where I can get rid of the
unorderable types error and then move on with fixing more errors?


Answer: Two things:

  * `int(0 if value is None else value)` doesn't accomplish anything because you are not saving the result -- maybe you meant `value = int(...)`?

  * `value = self.expr1.evaluate() < self.expr2.evaluate()` The `self.expr1.evaluate()` call is returning `None`, which is what causes your problem. So your next step is figure out why `None` is being returned from that expression. Note that `self.expr1` is _not_ None, its `evaluate` method is _returning_ None.

