Herramientas de usuario

Herramientas del sitio


wiki2:python:typing

Diferencias

Muestra las diferencias entre dos versiones de la página.

Enlace a la vista de comparación

Ambos lados, revisión anterior Revisión previa
Próxima revisión
Revisión previa
wiki2:python:typing [2022/03/14 17:42]
alfred
wiki2:python:typing [2022/10/12 19:03] (actual)
Línea 27: Línea 27:
       return self       return self
 </​code>​ </​code>​
 +
 +Several types:
 +<​code>​
 +Union[Union[int,​ str], float] == Union[int, str, float]
 +Union[int] == int
 +</​code>​
 +
 +Type or None:
 +''​Optional[X]''​ is equivalent to ''​X | None''​ (or ''​Union[X,​ None]''​).
 +<​code>​
 +Optional[str]
 +</​code>​
 +
 +Class type:
 +<​code>​
 +class ShopifyPostView(MethodView):​
 +    shopify_request_schema:​ t.Union[
 +        t.Type[ShopifyPaymentsRequest],​
 +        t.Type[ShopifyRefundsRequest],​
 +    ] = None
 +</​code>​
 +
 +Object of the previous class type:
 +<​code>​
 +ShopifyRequestClass:​ t.Type = t.Optional[
 +    t.Union[
 +        t.Type[ShopifyPaymentsRequest],​
 +        t.Type[ShopifyRefundsRequest],​
 +    ]
 +]
 +
 +ShopifyRequest = t.Type[ShopifyRequestClass]
 +</​code>​
 +
 +====== Links ======
 +
 +  * https://​towardsdatascience.com/​12-beginner-concepts-about-type-hints-to-improve-your-python-code-90f1ba0ac49
  
wiki2/python/typing.1647279753.txt.gz · Última modificación: 2022/03/14 18:42 (editor externo)