Typing of return type of a generic function · Issue #8946 · python/mypy (original) (raw)
Navigation Menu
- Explore
- Pricing
Provide feedback
Saved searches
Use saved searches to filter your results more quickly
Appearance settings
Description
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:
- Are you reporting a bug, or opening a feature request?
Reporting Bug - Please insert below the code you are checking with mypy,
or a mock-up repro if the source is private. We would appreciate
if you try to simplify your case to a minimal repro.
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])
- What is the actual behavior/output?
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>]"
- What is the behavior/output you expect?
Actually since this answer https://stackoverflow.com/a/42226930 I would expect it work. It also worked in previsous versions. - What are the versions of mypy and Python you are using?
mypy 0.780
python 3.7.7
(You can freely edit this text, please remove all the lines
you believe are unnecessary.)