pylint-errors

E1129 (not-context-manager)

:x: Problematic code:

class Ctx:
    def __enter__(self):
        pass


with Ctx() as ctx:
    pass

:heavy_check_mark: Correct code:

class Ctx:
    def __enter__(self):
        pass

    def __exit__(self, *exc):
        pass


with Ctx() as ctx:
    pass

Rationale:

Used when an instance in a with statement doesn’t implement the context manager protocol(__enter__/__exit__).