Kian Power
Kian Power

Reputation: 1

What does 'Got nothing' mean, after running a doctest?

I am making a method to find the largest value in a binary tree and I think I did it right but when i run my doctest on it, it says the expected value but then says 'Got nothing'. I'm not sure what that means or why it is happening.

def best_apartment(self) -> None:
    """Return (one of) the apartment(s) with the best evaluation
    score in the BSTTree.
    >>> apartments = read_apartment_data("apartments.csv")[0:300]
    >>> bst = BSTTree()
    >>> bst.build_tree(apartments)
    >>> bst.best_apartment()
    PRIVATE: 80
    """

    if self.is_empty():
        return None

    current_node = self
    while current_node.right is not None:
        current_node = current_node.right

    return current_node.apartment

this is the code I have for the method

Upvotes: 0

Views: 93

Answers (1)

wjandrea
wjandrea

Reputation: 33169

"Got nothing" means there was no output.

In this case, it's because Python doesn't show None values. For example:

>>> None  # No output
>>> 
>>> lst = []
>>> lst.append(1)  # This function returns None, so there's no output
>>> lst
[1]

You can confirm this for yourself by simply copying the code from the doctest into an interactive session and running it.

So, the problem is that your function is returning None. Where does it do that? if self.is_empty():. Or, it's possible that current_node.apartment is None. Either way, the root problem is not in the code you've shown here.

Upvotes: 1

Related Questions