|
1 | 1 | import dataclasses
|
2 | 2 | from contextlib import ContextDecorator
|
3 | 3 | from contextvars import ContextVar
|
| 4 | +from copy import deepcopy |
4 | 5 | from typing import Union
|
5 | 6 |
|
6 | 7 | from taskbadger.internal import AuthenticatedClient
|
@@ -87,8 +88,8 @@ def __init__(self):
|
87 | 88 |
|
88 | 89 | def __enter__(self):
|
89 | 90 | self.stack.append((self.context, self.tags))
|
90 |
| - self.context = self.context.copy() |
91 |
| - self.tags = self.tags.copy() |
| 91 | + self.context = deepcopy(self.context) |
| 92 | + self.tags = deepcopy(self.tags) |
92 | 93 | return self
|
93 | 94 |
|
94 | 95 | def __exit__(self, *args):
|
@@ -116,17 +117,19 @@ def current(cls):
|
116 | 117 |
|
117 | 118 | class Badger(metaclass=MugMeta):
|
118 | 119 | def __init__(self, settings_or_mug=None):
|
| 120 | + self._session = ReentrantSession() |
| 121 | + self._scope = Scope() |
| 122 | + |
119 | 123 | if isinstance(settings_or_mug, Badger):
|
120 | 124 | self.settings = settings_or_mug.settings
|
| 125 | + self._scope.context = deepcopy(settings_or_mug._scope.context) |
| 126 | + self._scope.tags = deepcopy(settings_or_mug._scope.tags) |
121 | 127 | else:
|
122 | 128 | self.settings = settings_or_mug
|
123 | 129 |
|
124 |
| - self._session = ReentrantSession() |
125 |
| - self._scope = Scope() |
126 |
| - |
127 | 130 | def bind(self, settings, tags=None):
|
128 | 131 | self.settings = settings
|
129 |
| - self.scope().tags = tags or {} |
| 132 | + self._scope.tags = tags or {} |
130 | 133 |
|
131 | 134 | def session(self) -> ReentrantSession:
|
132 | 135 | return self._session
|
|
0 commit comments