Relative Content

Tag Archive for pythonmypy

Type hint issue

I have a python script and trying to add type hints to the code, Following is the sample code (without type hints the code works) using mypy.

type hinting an optional class method?

I have inherited a legacy project that has a Superclass which offers hooks for custom behaviors by invoking override functions in the subclasses. The superclass defines the attribute as None, and invokes the methods when the value is not None. It seems to be loosely based on ideas form zope.interface and protocols.

Mypy does not see my singleton class attribute. It throws [attr-defined] and [no-untyped-def]

class WaitService: _instance = None def __new__(cls, name: str = “Default”): if not cls._instance: cls._instance = super(WaitService, cls).__new__(cls) cls._instance.name = name return cls._instance if __name__ == ‘__main__’: w = WaitService(“at till 9pm”) print(w.name) I have a python singleton class above. It runs as expected but when I validate it with Mypy, I get the errors […]