Typing of return type of a generic function · Issue #8946 · python/mypy (original) (raw)

Skip to content

Provide feedback

Saved searches

Use saved searches to filter your results more quickly

Sign up

Appearance settings

@PeterLaudel

Description

@PeterLaudel

Note: if you are reporting a wrong signature of a function or a class in
the standard library, then the typeshed tracker is better suited
for this report: https://github.com/python/typeshed/issues

Please provide more information to help us understand the issue:

from typing import TypeVar, Type, Optional, List, cast

T = TypeVar("T")

def some_func(something: Type[T]) -> T: return "something"

some_func(Optional[str]) some_func(Type[str])

typing_test.py:7: error: Incompatible return value type (got "str", expected "T")
typing_test.py:10: error: Argument 1 to "some_func" has incompatible type "object"; expected "Type[<nothing>]"
typing_test.py:11: error: Argument 1 to "some_func" has incompatible type "object"; expected "Type[<nothing>]"

(You can freely edit this text, please remove all the lines
you believe are unnecessary.)