Repository: numpy/numpy
File: numpy/f2py/capi_maps.py (Python)

Code before:
        if 'kindselector' in var:
            if '*' in var['kindselector']:
                try:
                    ctype = f2cmap[var['kindselector']['*']]
                except KeyError:
                    raw_typespec = var['typespec']
                    star = var['kindselector']['*']
                    errmess(f'getctype: "{raw_typespec} * '
                            f'{star}" not supported.\n')
            elif 'kind' in var['kindselector']:
                if typespec + 'kind' in f2cmap_all:
                    f2cmap = f2cmap_all[typespec + 'kind']
                try:
                    ctype = f2cmap[var['kindselector']['kind']]
                except KeyError:
                    if typespec in f2cmap_all:
                        f2cmap = f2cmap_all[typespec]
                    try:
                        ctype = f2cmap[str(var['kindselector']['kind'])]
                    except KeyError:
                        kind = var['kindselector']['kind']
                        errmess(f'getctype: "{typespec}'
                                f'({kind=})" is mapped to C '
                                f'"{ctype}" (to override define dict({typespec} = '
                                f'dict({kind}="<C typespec>")) '
                                f'in {os.getcwd()}/.f2py_f2cmap file).\n')
    elif not isexternal(var):
        errmess(f'getctype: No C-type found in "{var}", assuming void.\n')
    return ctype


def f2cexpr(expr):
    """Rewrite Fortran expression as f2py supported C expression.

    Due to the lack of a proper expression parser in f2py, this
    function uses a heuristic approach that assumes that Fortran
    arithmetic expressions are valid C arithmetic expressions when
    mapping Fortran function calls to the corresponding C function/CPP
    macros calls.

    """
    # TODO: support Fortran `len` function with optional kind parameter
    expr = re.sub(r'\blen\b', 'f2py_slen', expr)
    return expr


def getstrlength(var):
    if isstringfunction(var):
        if 'result' in var:
            a = var['result']
        else:

Review comment (suggestion):
nit:

```suggestion
                        errmess(f'getctype: "{typespec}({kind=})" is mapped to C '
                                f'"{ctype}" (to override define dict({typespec} = '
                                f'dict({kind}="<C typespec>")) '
                                f'in {os.getcwd()}/.f2py_f2cmap file).\n')
```

Code after:
        if 'kindselector' in var:
            if '*' in var['kindselector']:
                try:
                    ctype = f2cmap[var['kindselector']['*']]
                except KeyError:
                    raw_typespec = var['typespec']
                    star = var['kindselector']['*']
                    errmess(f'getctype: "{raw_typespec} * {star}" not supported.\n')
            elif 'kind' in var['kindselector']:
                if typespec + 'kind' in f2cmap_all:
                    f2cmap = f2cmap_all[typespec + 'kind']
                try:
                    ctype = f2cmap[var['kindselector']['kind']]
                except KeyError:
                    if typespec in f2cmap_all:
                        f2cmap = f2cmap_all[typespec]
                    try:
                        ctype = f2cmap[str(var['kindselector']['kind'])]
                    except KeyError:
                        kind = var['kindselector']['kind']
                        errmess(f'getctype: "{typespec}({kind=})" is mapped to C '
                                f'"{ctype}" (to override define {{{typespec!r}: '
                                f'{{{kind!r}: "<C typespec>"}}}} '
                                f'in {os.getcwd()}/.f2py_f2cmap file).\n')
    elif not isexternal(var):
        errmess(f'getctype: No C-type found in "{var}", assuming void.\n')
    return ctype


def f2cexpr(expr):
    """Rewrite Fortran expression as f2py supported C expression.

    Due to the lack of a proper expression parser in f2py, this
    function uses a heuristic approach that assumes that Fortran
    arithmetic expressions are valid C arithmetic expressions when
    mapping Fortran function calls to the corresponding C function/CPP
    macros calls.

    """
    # TODO: support Fortran `len` function with optional kind parameter
    expr = re.sub(r'\blen\b', 'f2py_slen', expr)
    return expr


def getstrlength(var):
    if isstringfunction(var):
        if 'result' in var:
            a = var['result']
        else:
            a = var['name']
        if a in var['vars']: