Skip to content

Commit 634e87d

Browse files
authored
fea: refactor core code and comment (#104)
1 parent 6ebd80f commit 634e87d

2 files changed

Lines changed: 4 additions & 60 deletions

File tree

objwatch/core.py

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,7 @@ def __init__(
4747
with_globals (bool): Enable tracing and logging of global variables across function calls.
4848
"""
4949
# Create configuration parameters for ObjWatch
50-
config = ObjWatchConfig(
51-
targets=targets,
52-
exclude_targets=exclude_targets,
53-
framework=framework,
54-
indexes=indexes,
55-
output=output,
56-
output_xml=output_xml,
57-
level=level,
58-
simple=simple,
59-
wrapper=wrapper,
60-
with_locals=with_locals,
61-
with_globals=with_globals,
62-
)
50+
config = ObjWatchConfig(**{k: v for k, v in locals().items() if k != 'self'})
6351

6452
# Create and configure the logger based on provided parameters
6553
create_logger(output=config.output, level=config.level, simple=config.simple)
@@ -136,19 +124,7 @@ def watch(
136124
ObjWatch: The initialized and started ObjWatch instance.
137125
"""
138126
# Instantiate the ObjWatch with the provided configuration
139-
obj_watch = ObjWatch(
140-
targets=targets,
141-
exclude_targets=exclude_targets,
142-
framework=framework,
143-
indexes=indexes,
144-
output=output,
145-
output_xml=output_xml,
146-
level=level,
147-
simple=simple,
148-
wrapper=wrapper,
149-
with_locals=with_locals,
150-
with_globals=with_globals,
151-
)
127+
obj_watch = ObjWatch(**locals())
152128

153129
# Start the tracing process
154130
obj_watch.start()

objwatch/tracer.py

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -104,21 +104,7 @@ def call_depth(self, value: int) -> None:
104104
self._call_depth = value
105105

106106
def _build_target_index(self):
107-
"""Build fast lookup indexes for monitoring targets.
108-
109-
Creates three-level indexes:
110-
- module_index: Set of monitored module names
111-
- class_index: Nested mapping of modules to their classes
112-
- function_index: Nested mapping of modules to their functions
113-
- global_index: Nested mapping of modules to their global variables
114-
115-
Final structure example:
116-
index_map = {
117-
'class': {'module1': {'ClassA', 'ClassB'}, ...},
118-
'function': {'module1': {'func1', 'func2'}, ...},
119-
'global': {'module1': {'var1', 'var2'}, ...}
120-
}
121-
"""
107+
"""Build fast lookup indexes for monitoring targets."""
122108
self.module_index = set(self.targets.keys())
123109
self.class_index = {}
124110
self.method_index = {}
@@ -169,25 +155,7 @@ def _build_target_index(self):
169155
}
170156

171157
def _build_exclude_target_index(self):
172-
"""Build fast lookup indexes for exclusion targets.
173-
174-
Creates indexes for exclusion targets similar to _build_target_index:
175-
- exclude_module_index: Set of excluded module names
176-
- exclude_class_index: Nested mapping of modules to their excluded classes
177-
- exclude_method_index: Nested mapping of modules to their excluded methods
178-
- exclude_attribute_index: Nested mapping of modules to their excluded attributes
179-
- exclude_function_index: Nested mapping of modules to their excluded functions
180-
- exclude_global_index: Nested mapping of modules to their excluded global variables
181-
182-
Final structure example:
183-
exclude_index_map = {
184-
'class': {'module1': {'ClassA', 'ClassB'}, ...},
185-
'method': {'module1': {'ClassA': {'method1', 'method2'}, ...}, ...},
186-
'attribute': {'module1': {'ClassA': {'attr1', 'attr2'}, ...}, ...},
187-
'function': {'module1': {'func1', 'func2'}, ...},
188-
'global': {'module1': {'var1', 'var2'}, ...}
189-
}
190-
"""
158+
"""Build fast lookup indexes for exclusion targets."""
191159
self.exclude_module_index = set(self.exclude_targets.keys())
192160
self.exclude_class_index = {}
193161
self.exclude_method_index = {}

0 commit comments

Comments
 (0)