Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
23a92baa
Commit
23a92baa
authored
Jul 26, 2015
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adapt metaclass usage to Py2/Py3
parent
595502fc
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
11 deletions
+52
-11
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+9
-4
Cython/Debugger/Tests/test_libcython_in_gdb.py
Cython/Debugger/Tests/test_libcython_in_gdb.py
+7
-5
Cython/Debugger/libpython.py
Cython/Debugger/libpython.py
+19
-2
Cython/Utils.py
Cython/Utils.py
+17
-0
No files found.
Cython/Compiler/Nodes.py
View file @
23a92baa
...
...
@@ -33,6 +33,7 @@ from .StringEncoding import EncodedString, escape_byte_string, split_string_lite
from
.
import
Future
from
.
import
Options
from
.
import
DebugFlags
from
..Utils
import
add_metaclass
absolute_path_length
=
0
...
...
@@ -178,15 +179,19 @@ class CheckAnalysers(type):
return
super
(
CheckAnalysers
,
cls
).
__new__
(
cls
,
name
,
bases
,
attrs
)
def
_with_metaclass
(
cls
):
if
DebugFlags
.
debug_trace_code_generation
:
return
add_metaclass
(
VerboseCodeWriter
)(
cls
)
#return add_metaclass(CheckAnalysers)(cls)
return
cls
@
_with_metaclass
class
Node
(
object
):
# pos (string, int, int) Source file position
# is_name boolean Is a NameNode
# is_literal boolean Is a ConstNode
#__metaclass__ = CheckAnalysers
if
DebugFlags
.
debug_trace_code_generation
:
__metaclass__
=
VerboseCodeWriter
is_name
=
0
is_none
=
0
is_nonecheck
=
0
...
...
Cython/Debugger/Tests/test_libcython_in_gdb.py
View file @
23a92baa
...
...
@@ -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
...
...
Cython/Debugger/libpython.py
View file @
23a92baa
...
...
@@ -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
):
...
...
Cython/Utils.py
View file @
23a92baa
...
...
@@ -414,3 +414,20 @@ class LazyStr:
def
__radd__
(
self
,
left
):
return
left
+
self
.
callback
()
# Class decorator that adds a metaclass and recreates the class with it.
# Copied from 'six'.
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment