@@ -250,6 +250,78 @@ For the complete mapping rules, see
250250
251251---
252252
253+ ## Inheritance And Polymorphic Input Dispatch
254+
255+ Fortran extension types generate a matching Python inheritance hierarchy.
256+ Inherited fields and methods remain available on the derived class, and an
257+ overridden type-bound method uses the derived implementation.
258+
259+ ``` fortran
260+ type :: base_shape
261+ real(8) :: size
262+ contains
263+ procedure :: area => base_area
264+ procedure :: set_size => base_set_size
265+ end type base_shape
266+
267+ type, extends(base_shape) :: circle
268+ real(8) :: radius
269+ contains
270+ procedure :: area => circle_area
271+ end type circle
272+
273+ contains
274+
275+ real(8) function base_area(self) result(value)
276+ class(base_shape), intent(in) :: self
277+ value = self%size
278+ end function base_area
279+
280+ subroutine base_set_size(self, value)
281+ class(base_shape), intent(inout) :: self
282+ real(8), intent(in) :: value
283+ self%size = value
284+ end subroutine base_set_size
285+
286+ real(8) function circle_area(self) result(value)
287+ class(circle), intent(in) :: self
288+ value = acos(-1.0_8) * self%radius * self%radius
289+ end function circle_area
290+ ```
291+
292+ For a wrapped module imported as ` shapes ` , the generated classes preserve that
293+ relationship:
294+
295+ ``` python
296+ shape = shapes.circle()
297+ assert isinstance (shape, shapes.base_shape)
298+
299+ shape.set_size(np.float64(5.0 ))
300+ shape.radius = np.float64(2.0 )
301+ print (shape.size) # inherited field: 5.0
302+ print (shape.area()) # overridden method: about 12.5664
303+ ```
304+
305+ A required scalar ` class(base), intent(in) ` argument accepts wrapped instances
306+ from the known base and descendant classes:
307+
308+ ``` fortran
309+ real(8) function describe_shape(item) result(value)
310+ class(base_shape), intent(in) :: item
311+ value = item%area()
312+ end function describe_shape
313+ ```
314+
315+ ``` python
316+ print (shapes.describe_shape(shape)) # about 12.5664
317+ ```
318+
319+ This polymorphic boundary is intentionally limited to required scalar inputs.
320+ Polymorphic outputs, mutable arguments, arrays, allocatable or pointer scalars,
321+ and unlimited polymorphism (` class(*) ` ) are not supported.
322+
323+ ---
324+
253325## Type-Bound Generics
254326
255327A type-bound generic groups several concrete methods under one Python method.
0 commit comments