[Lldb-commits] [PATCH] D14395: Fix some portability issues in unittest2

Zachary Turner via lldb-commits lldb-commits at lists.llvm.org
Thu Nov 5 14:12:16 PST 2015


zturner created this revision.
zturner added a reviewer: tfiala.
zturner added a subscriber: lldb-commits.

    TBH I'm honestly not sure what the problem was before, or why this fixes
    it.  But what I can tell from debugging is that under Py3,
    `sortMethodsUsing` is treated as a class attribute, but it was being
    accessed as `self.sortMethodsUsing`.  What the full implications of this
    are I don't quite know, but the symptom here was that the value we were
    assigning to it -- the global lambda `cmp_` -- was being treated as a
    bound method instead of a global method.  So it was expecting to be called
    with a `self` argument.

    Why exactly this happens in Python 3, and why exactly this *doesn't*
    happen in Python 2 are not clear to me.

It's worth mentioning that I tried to switch unittest2 over to unittest -- the builtin implementation -- as a means of solving the Py2 / Py3 portability problems, and it was non-trivial at best, at least with my limited Python knowledge.  The reason is that we have many custom decorators that rely on internals of unittest2 that are even documented in the source code as implementation details.  But we use them, and they don't exist in the Python 3 version of unittest2, and as a result I don't know how to do the port smoothly.

Honestly, I couldn't even get it working under Python 2.7's built-in unittest implementation for similar reasons (relying on implementation details).  It would be nice to do this someday, but our decorators have so many layers of wrapping and indirection that it makes my head explode trying to figure out what's going on :-/

http://reviews.llvm.org/D14395

Files:
  third_party/Python/module/unittest2/unittest2/__init__.py
  third_party/Python/module/unittest2/unittest2/loader.py
  third_party/Python/module/unittest2/unittest2/test/test_loader.py

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D14395.39416.patch
Type: text/x-patch
Size: 6558 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20151105/781968a2/attachment.bin>


More information about the lldb-commits mailing list