Skip to content

BUG: f2py generation loses intent specs on using --no-lower option #20943

Closed

Description

@dwr-psandhu

Describe the issue:

f2py generation of .pyf files works with default options but loses the intent specs when --no-lower is specified

See example below, its missing intent specs. If run without the --no-lower option it works fine.

Reproduce the code example:

f2py --no-lower -m testnl -h test_nolower.pyf

E.g. with a test file with this code
MODULE Test_Module
    IMPLICIT NONE
    CONTAINS
  SUBROUTINE Test_Routine(len_fname,fname,iStat) BIND(C,NAME='Test_Routine')
    INTEGER,INTENT(IN)    :: len_fname
    CHARACTER,INTENT(IN) :: fname(len_fname)
    INTEGER,INTENT(OUT)   :: iStat
  END SUBROUTINE
END MODULE

Error message:

!    -*- f90 -*-
! Note: the context of this file is case sensitive.

python module testnl ! in 
    interface  ! in :testnl
        module Test_Module ! in :testnl:test_f2py_intent.f90
            subroutine Test_Routine(len_fname,fname,iStat) ! in :testnl:test_f2py_intent.f90:Test_Module
                integer, optional,check(len(fname)>=len_fname),depend(fname) :: len_fname=len(fname)
                character dimension(len_fname) :: fname
                integer :: iStat
            end subroutine Test_Routine
        end module Test_Module
    end interface 
end python module testnl

! This file was auto-generated with f2py (version:1.21.2).
! See http://cens.ioc.ee/projects/f2py2e/

NumPy/Python version information:

1.21.2 3.7.11 (default, Jul 27 2021, 09:42:29) [MSC v.1916 64 bit (AMD64)]

Activity

  1. HaoZeke commented on Apr 28, 2022

    @HaoZeke
    Member

    --no-lower isn't actually doing what is expected (i.e. things are still in scream-case). Also, although the intent specs are present, they are also mangled.

    !    -*- f90 -*-
    ! Note: the context of this file is case sensitive.
    
    python module testnl ! in 
        interface  ! in :testnl
            module test_module ! in :testnl:repro.f90
                subroutine test_routine(len_fname,fname,istat) ! in :testnl:repro.f90:test_module
                    integer, optional,intent(in),check(shape(fname, 0) == len_fname),depend(fname) :: len_fname=shape(fname, 0)
                    character dimension(len_fname),intent(in) :: fname
                    integer intent(out) :: istat
                end subroutine test_routine
            end module test_module
        end interface 
    end python module testnl
    
    ! This file was auto-generated with f2py (version:1.23.0.dev0+1087.g0eaa40db3).
    ! See:
    ! https://web.archive.org/web/20140822061353/http://cens.ioc.ee/projects/f2py2e
    

    Note that the istat variable gets integer intent(out) :: istat instead of integer, intent(out).

    Then again, it also is unclear why it is valid to pass --no-lower to what is clearly not F77 code (module / bind(c) are both F90 features). A warning should be issued.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions