Tag: MYPY
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
Estoy tratando de obtener una lista de instancias de clase para clases que heredan de una clase padre en Python mientras uso MyPy. Tengo las siguientes clases de Python: animal.py from abc import abstractmethod from typing import Dict class Animal(): @property @abstractmethod def id(self) -> str: pass @property @abstractmethod def . . . Read more
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
Tengo una clase abstracta llamada ABC que tendrá una variable de instancia, digamos record, en todas sus clases de implementación. Para mejorar la legibilidad, quiero que los lectores sepan que las instancias de esa ABC deben tener una variable de instancia llamada record. Sin embargo, el tipo de record varía . . . Read more
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