File tree Expand file tree Collapse file tree 2 files changed +9
-3
lines changed Expand file tree Collapse file tree 2 files changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -20,12 +20,14 @@ def inherited(subclass)
2020 subclass . instance_variable_set ( :@__pyptr__ , __pyptr__ )
2121 end
2222
23- def new ( *args )
24- wrap_pyptr ( LibPython ::Helpers . call_object ( __pyptr__ , *args ) )
23+ def new ( *args , &b )
24+ wrap_pyptr ( LibPython ::Helpers . call_object ( __pyptr__ , *args ) ) . tap do |obj |
25+ obj . instance_eval { initialize ( &b ) }
26+ end
2527 end
2628
2729 def wrap_pyptr ( pyptr )
28- return pyptr if pyptr . kind_of? self
30+ return pyptr if pyptr . class <= self
2931 pyptr = pyptr . __pyptr__ if pyptr . kind_of? PyObjectWrapper
3032 unless pyptr . kind_of? PyPtr
3133 raise TypeError , "unexpected argument type #{ pyptr . class } (expected PyCall::PyPtr)"
Original file line number Diff line number Diff line change 1313 Class . new ( superclass_wrapper )
1414 end
1515
16+ it 'is an instance of subclass' do
17+ expect ( subclass . new . class ) . to eq ( subclass )
18+ end
19+
1620 it 'calls __init__ of superclass' do
1721 a = subclass . new ( 1 , 2 , 3 )
1822 expect ( a . init_args . to_a ) . to eq ( [ 1 , 2 , 3 ] )
You can’t perform that action at this time.
0 commit comments