Skip to content

Commit 914bbbb

Browse files
P403n1x87Yun-Kim
authored andcommitted
refactor(debugging): make safety module internal (#6810)
The safety submodule of `ddtrace.debugging` has been made public (according to the naming conventions) by accident. The API of this module is not documented and we do not expect any usage outside the library itself. ## Checklist - [x] Change(s) are motivated and described in the PR description. - [x] Testing strategy is described if automated tests are not included in the PR. - [x] Risk is outlined (performance impact, potential for breakage, maintainability, etc). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] [Library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) are followed. If no release note is required, add label `changelog/no-changelog`. - [x] Documentation is included (in-code, generated user docs, [public corp docs](https://github.com/DataDog/documentation/)). - [x] Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Title is accurate. - [x] No unnecessary changes are introduced. - [x] Description motivates each change. - [x] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes unless absolutely necessary. - [x] Testing strategy adequately addresses listed risk(s). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] Release note makes sense to a user of the library. - [x] Reviewer has explicitly acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment. - [x] Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting) - [x] If this PR touches code that signs or publishes builds or packages, or handles credentials of any kind, I've requested a review from `@DataDog/security-design-and-guidance`. - [x] This PR doesn't touch any of that. --------- Co-authored-by: Yun Kim <[email protected]> Co-authored-by: Yun Kim <[email protected]>
1 parent 0e6eaf6 commit 914bbbb

File tree

6 files changed

+16
-16
lines changed

6 files changed

+16
-16
lines changed

ddtrace/debugging/_expressions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
from bytecode import Compare
4141
from bytecode import Instr
4242

43-
from ddtrace.debugging.safety import safe_getitem
43+
from ddtrace.debugging._safety import safe_getitem
4444
from ddtrace.internal.compat import PYTHON_VERSION_INFO as PY
4545

4646

File renamed without changes.

ddtrace/debugging/_signal/model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import six
1616

1717
from ddtrace.context import Context
18-
from ddtrace.debugging import safety
18+
from ddtrace.debugging import _safety
1919
from ddtrace.debugging._expressions import DDExpressionEvaluationError
2020
from ddtrace.debugging._probe.model import FunctionLocationMixin
2121
from ddtrace.debugging._probe.model import LineLocationMixin
@@ -83,7 +83,7 @@ def _eval_condition(self, _locals=None):
8383
return False
8484

8585
def _enrich_args(self, retval, exc_info, duration):
86-
_locals = list(self.args or safety.get_args(self.frame))
86+
_locals = list(self.args or _safety.get_args(self.frame))
8787
_locals.append(("@duration", duration / 1e6)) # milliseconds
8888
if exc_info[1] is None:
8989
_locals.append(("@return", retval))

ddtrace/debugging/_signal/snapshot.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import attr
1010

11-
from ddtrace.debugging import safety
11+
from ddtrace.debugging import _safety
1212
from ddtrace.debugging._expressions import DDExpressionEvaluationError
1313
from ddtrace.debugging._probe.model import CaptureLimits
1414
from ddtrace.debugging._probe.model import DEFAULT_CAPTURE_LIMITS
@@ -144,7 +144,7 @@ def enter(self):
144144

145145
probe = self.probe
146146
frame = self.frame
147-
_args = list(self.args or safety.get_args(frame))
147+
_args = list(self.args or _safety.get_args(frame))
148148

149149
if probe.evaluate_at == ProbeEvaluateTimingForMethod.EXIT:
150150
return
@@ -190,7 +190,7 @@ def exit(self, retval, exc_info, duration):
190190

191191
if probe.take_snapshot:
192192
self.return_capture = _capture_context(
193-
self.args or safety.get_args(self.frame), _locals, exc_info, limits=probe.limits
193+
self.args or _safety.get_args(self.frame), _locals, exc_info, limits=probe.limits
194194
)
195195
self.duration = duration
196196
self.state = SignalState.DONE
@@ -213,8 +213,8 @@ def line(self):
213213
return
214214

215215
self.line_capture = _capture_context(
216-
self.args or safety.get_args(frame),
217-
safety.get_locals(frame),
216+
self.args or _safety.get_args(frame),
217+
_safety.get_locals(frame),
218218
sys.exc_info(),
219219
limits=probe.limits,
220220
)

ddtrace/debugging/_signal/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from ddtrace.debugging._probe.model import MAXLEN
1414
from ddtrace.debugging._probe.model import MAXLEVEL
1515
from ddtrace.debugging._probe.model import MAXSIZE
16-
from ddtrace.debugging.safety import get_fields
16+
from ddtrace.debugging._safety import get_fields
1717
from ddtrace.internal.compat import BUILTIN_CONTAINER_TYPES
1818
from ddtrace.internal.compat import BUILTIN_SIMPLE_TYPES
1919
from ddtrace.internal.compat import CALLABLE_TYPES

tests/debugging/test_safety.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
import pytest
66

7-
from ddtrace.debugging import safety
7+
from ddtrace.debugging import _safety
88

99

1010
def test_get_args():
1111
def assert_args(args):
12-
assert set(dict(safety.get_args(inspect.currentframe().f_back)).keys()) == args
12+
assert set(dict(_safety.get_args(inspect.currentframe().f_back)).keys()) == args
1313

1414
def assert_locals(_locals):
15-
assert set(dict(safety.get_locals(inspect.currentframe().f_back)).keys()) == _locals
15+
assert set(dict(_safety.get_locals(inspect.currentframe().f_back)).keys()) == _locals
1616

1717
def arg_and_kwargs(a, **kwargs):
1818
assert_args({"a", "kwargs"})
@@ -55,7 +55,7 @@ def property_with_side_effect(self):
5555

5656

5757
def test_get_fields_side_effects():
58-
assert safety.get_fields(SideEffects()) == {}
58+
assert _safety.get_fields(SideEffects()) == {}
5959

6060

6161
# ---- Slots ----
@@ -75,8 +75,8 @@ def __init__(self):
7575
super(B, self).__init__()
7676
self.b = "b"
7777

78-
assert safety.get_fields(A()) == {"a": "a"}
79-
assert safety.get_fields(B()) == {"a": "a", "b": "b"}
78+
assert _safety.get_fields(A()) == {"a": "a"}
79+
assert _safety.get_fields(B()) == {"a": "a", "b": "b"}
8080

8181

8282
def test_safe_dict():
@@ -87,4 +87,4 @@ def __dict__(self):
8787
raise NotImplementedError()
8888

8989
with pytest.raises(AttributeError):
90-
safety._safe_dict(Foo())
90+
_safety._safe_dict(Foo())

0 commit comments

Comments
 (0)