mypy generics - limit the types by listing
from typing import TypeVar
T = TypeVar('T', int, str)
def add(x: T, y: T) -> T:
return x + y
add(2, 3)
Press ← or → to navigate between chapters
Press S or / to search in the book
Press ? to show this help
Press Esc to hide this help
from typing import TypeVar
T = TypeVar('T', int, str)
def add(x: T, y: T) -> T:
return x + y
add(2, 3)