from typing import TypeVar T = TypeVar('T') def my_function(arg1: T, arg2: T) -> T: if type(arg1) != type(arg2): raise ValueError("Both arguments must be of the same type") return arg1
from typing import TypeVar, Generic, List T = TypeVar('T') class Queue(Generic[T]): def __init__(self): self.items: List[T] = [] def add_item(self, item: T): self.items.append(item) def get_item(self) -> T: return self.items.pop(0)In the above example, we define a `Queue` class that accepts a generic type `T`. We define the `items` attribute as a list of type `T`. The `add_item` method adds an item of type `T` to the queue, and the `get_item` method removes and returns the first item of type `T` from the queue. The TypeVar module is part of the Python Standard Library and does not require any additional package or library to be installed.