es.davy.ai

Preguntas y respuestas de programación confiables

¿Tienes una pregunta?

Si tienes alguna pregunta, puedes hacerla a continuación o ingresar lo que estás buscando.

Tag: STRONG-TYPING

MiPy, estrechamiento de tipo desde valores de retorno.

Estoy analizando el siguiente ejemplo de Python escrito: from future import annotations from typing import Optional class Thing: def does_intersect(self, other: Thing) -> bool: return True def intersect(self, other: Thing) -> Optional[Thing]: if self.does_intersect(other): return self else: return None def my_function() -> Thing: thing = Thing() other_thing = Thing() if . . . Read more

¿Es “Pythonico” verificar tipos de argumentos de función?

Procedente del entorno de C/C++, siempre me ha desconcertado la falta de comprobación de tipos de Python. Por ello, siempre he tendido a escribir código de este tipo: def function(this_debería_ser_lista, this_debería_ser_entero): isFristArgList = isinstance(this_debería_ser_lista,list) if not isFristArgList: raise Exception(“¡El primer argumento debería ser una lista!”) isSecondArgInt = isinstance(this_debería_ser_entero,int) if not . . . Read more