PEP 695 introduces type parameters on function and classes in python 3.12, which are currently not considered when formatting, but should be added:
class ClassA[T: str]:
def method1(self) -> T:
...
def func[T](a: T, b: T) -> T:
...
Their implementation can likely reuse larger parts of dict comprehensions. See psf/black#3703 for the black implementation