LMPTHW Ex 17 issues with Ex 14 implementation

Running the test for the Zed’s dictionary code, it hits an error in my implementation of the doubly linked list from Ex 14. I started by typing out the dictionary source code and then ended up copying and pasting it so I know that that is not the issue. It also runs fine with the solution code found in the solutions repository.

You can find my implementation of the doubly linked list here.

The error I get when running the tests is as follows:

Traceback (most recent call last):
  File "dicTest.py", line 6, in <module>
    states.set('Oregon',    'OR')
  File "C:\Users\redacted\Algorithms\dictionary.py", line 54, in set
    bucket.push((key, value))
AttributeError: 'NoneType' object has no attribute 'push'

I know that somewhere I am having an issue handling None - something is not working the way I expect it to - but I am totally lost as to where this is coming from. I need a second pair of eyes on my code. Can anyone help me find the original source of the error?
Also feel free to point out any other issues with my implementation.

Hmm, so that means that your bucket is None at that point, which says to me the error is actually in some algorithm you depend on in this. It might be in your linked list implementation, but it could also be in how you have written the test. What you should do is this trick I’m kind of liking lately for quick debugging:

At the top put:

import pdb

That’s the python debugger. Now right before this line of code, 54, do this:


That will drop into the python debugger right at that point and then you can inspect what’s there. You can then print out what you need to figure it out, move the set_trace() to where you think the problem is, and get an idea of what’s going on.

Keep in mind that my tests are run when I build the book so if there was an error in them then it’d be shown in the book like yours. That means you have to rule out your code before assuming it’s mine (even though it could totally be mine, just less likely).

Thanks for the tip Zed. Now I’m off to teach myself one more thing I’ve been putting off.