From f3f81f36338bac268a9eb635a58025b40f4a1a5e Mon Sep 17 00:00:00 2001 From: Sven Sager Date: Thu, 7 Nov 2024 11:24:22 +0100 Subject: [PATCH] refactor: Show deprecation warning on root context manager This context manager can delete the entire instance of ModIO when using `with rpi:` after creating an instance of ModIO by `rpi = revpimodio.RevPiModIO(...)`. --- src/revpimodio2/modio.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/revpimodio2/modio.py b/src/revpimodio2/modio.py index cde5e22..d7c73b1 100644 --- a/src/revpimodio2/modio.py +++ b/src/revpimodio2/modio.py @@ -208,6 +208,19 @@ class RevPiModIO(object): self._myfh.close() def __enter__(self): + # todo: Remove this context manager in future + warnings.warn( + "This context manager is deprecated and will be removed!\n\n" + "You should use the context manager of the IO object `with revpi.io:` " + "or with a single device `with revpi.device.my_device:`.\n\n" + "This deprecated context manager can be reproduced as follows:\n" + "```" + "revpi = revpimodio2.RevPiModIO()" + "with revpi.io:" + " ..." + "```", + DeprecationWarning, + ) if self._context_manager: raise RuntimeError("can not use multiple context managers of same instance") if self._looprunning: