Skip to content

Commit 8d09107

Browse files
committed
Add PyObjectWrapper#kind_of?
1 parent 6108612 commit 8d09107

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

lib/pycall/pyobject_wrapper.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ def respond_to_missing?(name, include_private)
5151
super
5252
end
5353

54+
def kind_of?(cls)
55+
case cls
56+
when PyTypeObjectWrapper
57+
__pyptr__.kind_of?(cls.__pyptr__)
58+
else
59+
super
60+
end
61+
end
62+
5463
[:==, :!=, :<, :<=, :>, :>=].each do |op|
5564
class_eval("#{<<-"begin;"}\n#{<<-"end;"}", __FILE__, __LINE__+1)
5665
begin;

spec/pycall/conversion_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ module PyCall
1616
end
1717

1818
it 'returns true and registers a given type mapping' do
19-
expect(LibPython::Helpers.call_object(python_class)).not_to be_a(wrapper_class)
19+
expect(LibPython::Helpers.call_object(python_class).class).not_to eq(wrapper_class)
2020
expect(Conversion.register_python_type_mapping(python_class, wrapper_class)).to eq(true)
21-
expect(LibPython::Helpers.call_object(python_class)).to be_a(wrapper_class)
21+
expect(LibPython::Helpers.call_object(python_class).class).to eq(wrapper_class)
2222
end
2323

2424
context 'when no type mapping for a given Python type is registered' do
@@ -70,7 +70,7 @@ module PyCall
7070
it 'returns true and unregisters the type mapping for a given Python type' do
7171
Conversion.register_python_type_mapping(python_class, wrapper_class)
7272
expect(Conversion.unregister_python_type_mapping(python_class)).to eq(true)
73-
expect(LibPython::Helpers.call_object(python_class)).not_to be_a(wrapper_class)
73+
expect(LibPython::Helpers.call_object(python_class).class).not_to eq(wrapper_class)
7474
end
7575

7676
context 'when the type mapping for a given Python type is not registered' do

0 commit comments

Comments
 (0)