diff options
author | Stefan Behnel <stefan_ml@behnel.de> | 2015-07-26 11:08:25 +0200 |
---|---|---|
committer | Stefan Behnel <stefan_ml@behnel.de> | 2015-07-26 11:08:25 +0200 |
commit | 23a92baa1409407a63c2ffc2addb5a43d3a99508 (patch) | |
tree | 4c3d3a787a750ead68dede30f930ef0a107465bd /Cython/Debugger | |
parent | 595502fc7be792a06bb073659edc3e2fb640929f (diff) | |
download | cython-23a92baa1409407a63c2ffc2addb5a43d3a99508.tar.gz |
adapt metaclass usage to Py2/Py3
Diffstat (limited to 'Cython/Debugger')
-rw-r--r-- | Cython/Debugger/Tests/test_libcython_in_gdb.py | 12 | ||||
-rw-r--r-- | Cython/Debugger/libpython.py | 21 |
2 files changed, 26 insertions, 7 deletions
diff --git a/Cython/Debugger/Tests/test_libcython_in_gdb.py b/Cython/Debugger/Tests/test_libcython_in_gdb.py index 8224b958a..b5fa48489 100644 --- a/Cython/Debugger/Tests/test_libcython_in_gdb.py +++ b/Cython/Debugger/Tests/test_libcython_in_gdb.py @@ -5,6 +5,8 @@ Note: debug information is already imported by the file generated by Cython.Debugger.Cygdb.make_command_file() """ +from __future__ import absolute_import + import os import re import sys @@ -21,9 +23,10 @@ from test import test_support import gdb -from Cython.Debugger import libcython -from Cython.Debugger import libpython -from Cython.Debugger.Tests import TestLibCython as test_libcython +from .. import libcython +from .. import libpython +from . import TestLibCython as test_libcython +from ...Utils import add_metaclass # for some reason sys.argv is missing in gdb sys.argv = ['gdb'] @@ -50,14 +53,13 @@ class TraceMethodCallMeta(type): setattr(self, func_name, print_on_call_decorator(func)) +@add_metaclass(TraceMethodCallMeta) class DebugTestCase(unittest.TestCase): """ Base class for test cases. On teardown it kills the inferior and unsets all breakpoints. """ - __metaclass__ = TraceMethodCallMeta - def __init__(self, name): super(DebugTestCase, self).__init__(name) self.cy = libcython.cy diff --git a/Cython/Debugger/libpython.py b/Cython/Debugger/libpython.py index 4c15c1e17..b43b83c10 100644 --- a/Cython/Debugger/libpython.py +++ b/Cython/Debugger/libpython.py @@ -183,6 +183,25 @@ class PrettyPrinterTrackerMeta(type): all_pretty_typenames.add(self._typename) +# Class decorator that adds a metaclass and recreates the class with it. +# Copied from 'six'. See Cython/Utils.py. +def _add_metaclass(metaclass): + """Class decorator for creating a class with a metaclass.""" + def wrapper(cls): + orig_vars = cls.__dict__.copy() + slots = orig_vars.get('__slots__') + if slots is not None: + if isinstance(slots, str): + slots = [slots] + for slots_var in slots: + orig_vars.pop(slots_var) + orig_vars.pop('__dict__', None) + orig_vars.pop('__weakref__', None) + return metaclass(cls.__name__, cls.__bases__, orig_vars) + return wrapper + + +@_add_metaclass(PrettyPrinterTrackerMeta) class PyObjectPtr(object): """ Class wrapping a gdb.Value that's a either a (PyObject*) within the @@ -195,8 +214,6 @@ class PyObjectPtr(object): to corrupt data, etc; this is the debugger, after all. """ - __metaclass__ = PrettyPrinterTrackerMeta - _typename = 'PyObject' def __init__(self, gdbval, cast_to=None): |