Skip to content

Type annotations using collections.abc.Callable not working ok #457

@chiuczek

Description

@chiuczek

According to the Python docs, typing.Callable is deprecated for type hinting, in favour of using collections.abc.Callable. When I replaced this usage in some of my code, pdoc3 fails to produce documentation. I have a minimal example which shows the issue (this was running on Python 3.10.16 with pdoc3 0.11.5)

from collections.abc import Callable
from typing import Callable as CallableTyping


def test_fn(
    in1: str, in2: str, in3: str|None
) -> Callable[[str], str]:
    """Test function"""
    def returned_fn(iput: str) -> str:
        print(iput)
        return f"Printed {iput}"

    return returned_fn

def test_fn_2(
    in1: str, in2: str, in3: str|None
) -> CallableTyping[[str], str]:
    """Test function"""
    def returned_fn2(iput: str) -> str:
        print(iput)
        return f"Printed {iput}"

    return returned_fn2

The first function will trip pdoc3 up, with the error TypeError: Expected a list of types, an ellipsis, ParamSpec, or Concatenate. Got (<class 'str'>,), while the second will be fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateThis issue or pull request already exists

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions