3

Is there a legal pythonic way to store one additional attribute in ContextVar?

I can't subclass ContextVar because of TypeError

I can

    from contextvars import ContextVar as BaseContextVar

    class ContextVar:
        def __init__(self, name, *, default: Optional[Any], key: Optional[str]):
            self._var = BaseContextVar(name, default=default)
            self.key = key

but I'm not sure that there will be no side effects

P. S. Of course, I can store additional values in mapping. But I don't like this

Belegnar
  • 721
  • 10
  • 24

0 Answers0