I have a bit of an odd use-case. I already have a context manager for all my CLI applications which provides a lot of useful non-functional concern tasks (e.g. config parsing, logging setup, response time calculation, etc), I call it BaseCLI
as follows:
class BaseCLI(object):
def __enter__(self):
# ... a lot of stuff
return config
def __exit__(self, type, value, traceback):
# exit implementation
I also have a DynamicScope
implementation similar to the one in this answer https://stackoverflow.com/a/63340335/1142881. I would like to plug a dynamic scope instance to be reused as part my existing BaseCLI
to do FLOP counting ... how can I do that? The DynamicScope
is also a context manager and ideally I would like to do:
from somewhere import myscope
with BaseClI(...) as config:
with myscope.assign(flop_count=0):
# ... count the flops in every inner scope
This I would need to do in every CLI instance and that's not ideal .. I would instead like to achieve the same effect from the BaseCLI
__enter__
implementation but don't know how ...