Skip to content

Commit e8ec59b

Browse files
yt-msMidnighter
authored andcommitted
fix: warn properly on calling deprecated methods
1 parent 177cdaf commit e8ec59b

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

src/structurizr/api/structurizr_client.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import hashlib
2121
import hmac
2222
import logging
23+
import warnings
2324
from base64 import b64encode
2425
from contextlib import contextmanager
2526
from datetime import datetime, timedelta, timezone
@@ -100,11 +101,13 @@ def __repr__(self) -> str:
100101
)
101102

102103
def __enter__(self):
103-
"""Enter a context by locking the corresponding remote workspace.
104-
105-
Note: this method is deprecated in favour of lock(), and will be removed in a
106-
future relesae.
107-
"""
104+
"""Enter a context by locking the corresponding remote workspace."""
105+
warnings.warn(
106+
"Using the `StructurizrClient` in a context is deprecated since version "
107+
"0.4.1 and will be removed in a future release. Please use the "
108+
"preferred method `.lock()` instead.",
109+
DeprecationWarning,
110+
)
108111
is_successful = self.lock_workspace()
109112
if not is_successful:
110113
raise StructurizrClientException(
@@ -114,11 +117,13 @@ def __enter__(self):
114117
return self
115118

116119
def __exit__(self, exc_type, exc_val, exc_tb):
117-
"""Exit a context by unlocking the corresponding remote workspace.
118-
119-
Note: this method is deprecated in favour of lock(), and will be removed in a
120-
future relesae.
121-
"""
120+
"""Exit a context by unlocking the corresponding remote workspace."""
121+
warnings.warn(
122+
"Using the `StructurizrClient` in a context is deprecated since version "
123+
"0.4.1 and will be removed in a future release. Please use the "
124+
"preferred method `.lock()` instead.",
125+
DeprecationWarning,
126+
)
122127
is_successful = self.unlock_workspace()
123128
self._client.close()
124129
if exc_type is None and not is_successful:
@@ -135,7 +140,7 @@ def lock(self):
135140
f"Failed to lock the Structurizr workspace {self.workspace_id}."
136141
)
137142
try:
138-
yield None
143+
yield self
139144
finally:
140145
is_successful = self.unlock_workspace()
141146
self._client.close()

0 commit comments

Comments
 (0)