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: MYPY

mypy strict no detecta los booleanos, devuelve ‘no-any-return’.

Para la siguiente función: def __eq__(self, other: object) -> bool: if not isinstance(other, Node): return False return other.address == self.address Mypy está reportando el error: error: Returning Any from function declared to return “bool” [no-any-return]. Esto parece extraño, ya que ambos enunciados de retorno claramente devuelven un booleano. ¿Alguien puede . . . Read more

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

Haz que mypy reconozca que el objeto tiene atributo.

from typing import Union, List, TypeVar foo: object if hasattr(foo, ‘bar’): print(foo.bar) returns main.py:6: error: “object” has no attribute “bar” Found 1 error in 1 file (checked 1 source file) However, we know that foo has attribute bar, because we just asserted it – is there any way to tell . . . Read more