Skip to content

Commit e9be777

Browse files
committed
Add PyTypeObjectWrapper#===
Fixes #29
1 parent 4a13af5 commit e9be777

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

lib/pycall/pytypeobject_wrapper.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@ def wrap_pyptr(pyptr)
3838
end
3939
end
4040

41+
def ===(other)
42+
case other
43+
when PyObjectWrapper
44+
__pyptr__ === other.__pyptr__
45+
when PyPtr
46+
__pyptr__ === other
47+
else
48+
super
49+
end
50+
end
51+
4152
private
4253

4354
def register_python_type_mapping

spec/pycall/pyobject_wrapper_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,12 @@ module PyCall
233233
end
234234
end
235235

236+
describe '#kind_of?' do
237+
specify do
238+
expect(PyCall.tuple()).to be_a(PyCall.builtins.tuple)
239+
end
240+
end
241+
236242
describe '#to_s' do
237243
subject(:dict) { PyCall::Dict.new(a: 1, b: 2, c: 3) }
238244

spec/pycall/pytypeobject_wrapper_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ module PyCall
1010
PyCall.wrap_class(simple_class)
1111
end
1212

13+
describe '#===' do
14+
specify do
15+
expect(PyCall.builtins.tuple === PyCall.tuple()).to eq(true)
16+
np = PyCall.import_module('numpy')
17+
expect(np.int64 === np.asarray([1])[0]).to eq(true)
18+
expect(np.integer === np.asarray([1])[0]).to eq(true)
19+
end
20+
end
21+
1322
describe '.extend_object' do
1423
context '@__pyptr__ of the extended object is a PyCall::PyTypePtr' do
1524
it 'extends the given object' do

0 commit comments

Comments
 (0)