Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
GNOME
pygobject
Commits
2fd3aa9d
Commit
2fd3aa9d
authored
Oct 29, 2011
by
Tomeu Vizoso
Browse files
Properly chain up to the class that implements a given vfunc.
https://bugzilla.gnome.org/show_bug.cgi?id=662994
parent
cfda820e
Changes
2
Hide whitespace changes
Inline
Side-by-side
gi/types.py
View file @
2fd3aa9d
...
...
@@ -48,15 +48,20 @@ def Function(info):
return
function
def
NativeVFunc
(
info
,
cls
):
class
NativeVFunc
(
object
):
def
native_vfunc
(
*
args
,
**
kwargs
):
return
info
.
invoke
(
cls
.
__gtype__
,
*
args
,
**
kwargs
)
native_vfunc
.
__info__
=
info
native_vfunc
.
__name__
=
info
.
get_name
()
native_vfunc
.
__module__
=
info
.
get_namespace
()
def
__init__
(
self
,
info
):
self
.
_info
=
info
def
__get__
(
self
,
instance
,
klass
):
def
native_vfunc
(
*
args
,
**
kwargs
):
return
self
.
_info
.
invoke
(
klass
.
__gtype__
,
*
args
,
**
kwargs
)
native_vfunc
.
__info__
=
self
.
_info
native_vfunc
.
__name__
=
self
.
_info
.
get_name
()
native_vfunc
.
__module__
=
self
.
_info
.
get_namespace
()
return
native_vfunc
return
native_vfunc
def
Constructor
(
info
):
...
...
@@ -147,7 +152,6 @@ class MetaClassHelper(object):
base_info
.
get_name
(),
ambiguous_base
.
__info__
.
get_namespace
(),
ambiguous_base
.
__info__
.
get_name
()))
hook_up_vfunc_implementation
(
vfunc_info
,
cls
.
__gtype__
,
py_vfunc
)
...
...
@@ -162,7 +166,7 @@ class MetaClassHelper(object):
for
vfunc_info
in
class_info
.
get_vfuncs
():
name
=
'do_%s'
%
vfunc_info
.
get_name
()
value
=
NativeVFunc
(
vfunc_info
,
cls
)
value
=
NativeVFunc
(
vfunc_info
)
setattr
(
cls
,
name
,
value
)
def
find_vfunc_info_in_interface
(
bases
,
vfunc_name
):
...
...
tests/test_gi.py
View file @
2fd3aa9d
...
...
@@ -1639,16 +1639,6 @@ class TestPythonGObject(unittest.TestCase):
self
.
assertTrue
(
'do_method_with_default_implementation'
in
GIMarshallingTests
.
Object
.
__dict__
)
self
.
assertTrue
(
'do_method_with_default_implementation'
not
in
GIMarshallingTests
.
SubObject
.
__dict__
)
# Here we check that accessing a vfunc from the subclass returns the same wrapper object,
# meaning that multiple wrapper objects have not been created for the same vfunc.
func1
=
GIMarshallingTests
.
Object
.
do_method_with_default_implementation
func2
=
GIMarshallingTests
.
SubObject
.
do_method_with_default_implementation
if
sys
.
version_info
<
(
3
,
0
):
func1
=
func1
.
im_func
func2
=
func2
.
im_func
self
.
assertTrue
(
func1
is
func2
)
def
test_subobject_with_interface_and_non_vfunc_do_method
(
self
):
# There was a bug for searching for vfuncs in interfaces. It was
# triggered by having a do_* method that wasn't overriding
...
...
@@ -1657,6 +1647,16 @@ class TestPythonGObject(unittest.TestCase):
def
do_method_not_a_vfunc
(
self
):
pass
def
test_subsubobject
(
self
):
class
SubSubSubObject
(
GIMarshallingTests
.
SubSubObject
):
def
do_method_deep_hierarchy
(
self
,
num
):
self
.
props
.
int
=
num
*
2
sub_sub_sub_object
=
SubSubSubObject
()
GIMarshallingTests
.
SubSubObject
.
do_method_deep_hierarchy
(
sub_sub_sub_object
,
5
)
self
.
assertEqual
(
sub_sub_sub_object
.
props
.
int
,
5
)
class
TestMultiOutputArgs
(
unittest
.
TestCase
):
def
test_int_out_out
(
self
):
...
...
Write
Preview
Supports
Markdown
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