From: Thomas V. S. <th...@ap...> - 2009-06-26 22:59:55
|
I spent half a day trying to figure out why the following simple code: def func(): d = { 'a': 1, 'b': 2} print d.keys() triggers, in python 2.6, the following warning: Object (d) has no attribute (keys) After lots of digging through undocumented code, learning more Python internals than I ever have before, learning about opcodes, getting decently good at using the dis module, and understanding that dict storage has changed in Python 2.6 to be more optimized, adding an opcode for STORE_MAP, I finally figured out that pychecker dispatches based on the opcode, and that, if there is no dispatcher, it just silently drops the opcode. My best guess as to why this is the behaviour is because there are some opcodes (like PRINT_NEWLINE) that probably don't do anything to the stack, so it was pointless to make a dispatch function for it. However, dropping by default also makes sure that new opcodes go undetected, causing very strange behaviour where it should probably error out. So, after sleeping off today's frustration, tomorrow I plan to: - make it error out if the dispatcher doesn't have a function for the opcode - add dummy dispatchers for the ones that make sense not to have one - add a dispatcher for STORE_MAP as best as I can figure out how to to fix my actual bug. Additionally, after being a little annoyed at the lack of documentation inside pychecker, I started documenting some of the methods. Since there doesn't seem to be a standard on how to document the arguments, I'll go for epydoc-compatible style for now unless someone prefers something else. I will probably also add a unit test that verifies that everything in dis.opmap is actually in the dispatcher. Since I'm rather new at this low level, feel free to let me know if you think I'm about to do something stupid tomorrow :) Thomas -- I go through all of this before you wake up So I can feel happier to be safe up here with you -- savon - Saving your work to svn https://apestaart.org/thomas/trac/ |