DEV Community

Johnnatan Sandoval Cardona
Johnnatan Sandoval Cardona

Posted on

Algo más de azúcar para python

Python 3.12 introdujo algo de azúcar sintáctica para definir clases y funciones genéricas. Veamos cómo funciona:

def max[T](args: Iterable[T]) -> T:
    ...

class list[T]:
    def __getitem__(self, index: int, /) -> T:
        ...

    def append(self, element: T) -> None:
        ...
Enter fullscreen mode Exit fullscreen mode

Se agradece esta simplificación que es útil en definiciones simples.

También es ahora permitido crear aliases con type, aunque aún no he tenido la oportunidad de usarlo. El proyecto en el que trabajo en este momento usa python 3.10.

type Point = tuple[float, float]
type Point[T] = tuple[T, T]
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more