Skip to content

Commit 87fdc25

Browse files
authored
Revert "Inspection Adapters Improvement"
1 parent 41ded5a commit 87fdc25

File tree

3 files changed

+10
-70
lines changed

3 files changed

+10
-70
lines changed

src/json_visitor/contextual_adapters/base_adapter.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
__version__ = r"1.1.0"
1+
__version__ = r"1.0.0"
22

3-
from typing import Any, Dict, Iterable, Tuple
3+
from typing import Any, Iterable, Tuple
44

55
from ..simple_adapters.scope_adapter import ScopeAdapter
66
from ..scoping.root_scope import RootScope
@@ -12,8 +12,8 @@ class BaseAdapter( ScopeAdapter ):
1212
This adapter tracks scope and stores data to implement higher-level callbacks.
1313
"""
1414

15-
def __init__( self, **kwargs: Dict[ str, Any ] ):
16-
super().__init__( **kwargs )
15+
def __init__( self ):
16+
super().__init__()
1717
self._persistent_data = True
1818

1919
def after_document_end( self ) -> None:

src/json_visitor/contextual_adapters/inspector_adapter.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,12 @@
1-
__version__ = r"1.1.0"
1+
__version__ = r"1.0.0"
22

3-
from typing import Any, Dict, Iterable, Tuple
3+
from typing import Any, Iterable, Tuple
44

55
from ..scoping.root_scope import RootScope
66
from .base_adapter import BaseAdapter
77
from ..simple_adapters.scope_inspector_adapter import ScopeInspectionAdapter
88

99
class InspectionAdapter( BaseAdapter, ScopeInspectionAdapter ):
10-
def __init__( self, **kwargs: Dict[ str, Any ] ):
11-
"""
12-
Creates a InspectionAdapter.
13-
14-
Keyword Arguments:
15-
`output_targets`: iterable of output targets.
16-
`open_file_mode`: file mode output targets will be opened with; defaults to write ("w").
17-
`output_console`: boolean which controls if stdout should be written to; defaults to True, indicating stdout will be written to.
18-
`output_error`: boolean which controls if stderr should be written to; defaults to False, indicating stderr will not be written to.
19-
"""
20-
21-
super().__init__( **kwargs )
22-
2310
def process_document( self, root_scope: RootScope ) -> None:
2411
super().process_document( root_scope )
2512

src/json_visitor/simple_adapters/scope_inspector_adapter.py

Lines changed: 4 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,14 @@
1-
__version__ = r"1.1.0"
1+
__version__ = r"1.0.0"
22

3-
from typing import Any, Dict, Iterable, List, Union, TextIO
4-
from io import TextIOWrapper
3+
from typing import Any, Iterable
54

6-
import sys
7-
from pathlib import Path
85
from .scope_adapter import ScopeAdapter
96

107
class ScopeInspectionAdapter( ScopeAdapter ):
11-
def __init__( self, **kwargs: Dict[ str, Any ] ):
12-
"""
13-
Creates a ScopeInspectionAdapter.
14-
15-
Keyword Arguments:
16-
`output_targets`: iterable of output targets.
17-
`open_file_mode`: file mode output targets will be opened with; defaults to write ("w").
18-
`output_console`: boolean which controls if stdout should be written to; defaults to True, indicating stdout will be written to.
19-
`output_error`: boolean which controls if stderr should be written to; defaults to False, indicating stderr will not be written to.
20-
"""
21-
8+
def __init__( self ):
229
super().__init__()
2310

24-
output_targets: Iterable[ str, Path, TextIO ] = kwargs.get( "output_targets", None )
25-
if output_targets is None:
26-
output_targets = []
27-
28-
open_file_mode = kwargs.get( "open_file_mode", None )
29-
if open_file_mode is None:
30-
open_file_mode: str = "w"
31-
32-
output_console: bool = bool( kwargs.get( "output_console", True ) )
33-
output_error: bool = bool( kwargs.get( "output_error", False ) )
34-
35-
self._output_targets: List[ TextIO ] = []
36-
37-
if output_console:
38-
self._output_targets.append( sys.stdout )
39-
40-
if output_error:
41-
self._output_targets.append( sys.stderr )
42-
43-
for target in output_targets:
44-
if isinstance( target, str ):
45-
target = Path( target )
46-
47-
if isinstance( target, Path ):
48-
target = open( target, open_file_mode )
49-
50-
if not isinstance( target, ( TextIO, TextIOWrapper ) ):
51-
raise ValueError( "Invalid scope inspection target: target must be a string, path, or text stream." )
52-
else:
53-
self._output_targets.append( target )
54-
55-
def _output_message( self, message: str ) -> None:
56-
for target in self._output_targets:
57-
print( message, file = target )
58-
target.flush()
11+
self._output_message = lambda message: print( message )
5912

6013
def _print_message( self, name, *values: Iterable[ Any ] ) -> None:
6114
if len( values ) > 0:

0 commit comments

Comments
 (0)