6464 'VarsPrinter' ,
6565 'VarsSnooper' ,
6666 'When' ,
67-
6867 'stop' ,
6968 'trace' ,
7069)
7170THREADING_SUPPORT_ALIASES = (
72- 'threading_support' , 'threads_support' , 'thread_support' ,
73- 'threadingsupport' , 'threadssupport' , 'threadsupport' ,
74- 'threading' , 'threads' , 'thread' ,
71+ 'threading_support' ,
72+ 'threads_support' ,
73+ 'thread_support' ,
74+ 'threadingsupport' ,
75+ 'threadssupport' ,
76+ 'threadsupport' ,
77+ 'threading' ,
78+ 'threads' ,
79+ 'thread' ,
7580)
7681TRACER_OPTION_NAMES = THREADING_SUPPORT_ALIASES + (
7782 'clear_env_var' ,
8691def _embed_via_environment ():
8792 if 'PYTHONHUNTER' in os .environ :
8893 try :
89- eval ('trace({[PYTHONHUNTER]})' .format (os .environ ), {
90- 'And' : And ,
91- 'Backlog' : Backlog ,
92- 'CallPrinter' : CallPrinter ,
93- 'CodePrinter' : CodePrinter ,
94- 'Debugger' : Debugger ,
95- 'ErrorSnooper' : ErrorSnooper ,
96- 'From' : From ,
97- 'Manhole' : Manhole ,
98- 'Not' : Not ,
99- 'Or' : Or ,
100- 'Q' : Q ,
101- 'Query' : Query ,
102- 'StackPrinter' : StackPrinter ,
103- 'VarsPrinter' : VarsPrinter ,
104- 'VarsSnooper' : VarsSnooper ,
105- 'When' : When ,
106- 'trace' : trace ,
107- })
94+ eval (
95+ 'trace({[PYTHONHUNTER]})' .format (os .environ ),
96+ {
97+ 'And' : And ,
98+ 'Backlog' : Backlog ,
99+ 'CallPrinter' : CallPrinter ,
100+ 'CodePrinter' : CodePrinter ,
101+ 'Debugger' : Debugger ,
102+ 'ErrorSnooper' : ErrorSnooper ,
103+ 'From' : From ,
104+ 'Manhole' : Manhole ,
105+ 'Not' : Not ,
106+ 'Or' : Or ,
107+ 'Q' : Q ,
108+ 'Query' : Query ,
109+ 'StackPrinter' : StackPrinter ,
110+ 'VarsPrinter' : VarsPrinter ,
111+ 'VarsSnooper' : VarsSnooper ,
112+ 'When' : When ,
113+ 'trace' : trace ,
114+ },
115+ )
108116 except Exception as exc :
109117 sys .stderr .write ('Failed to load hunter from PYTHONHUNTER environ variable {[PYTHONHUNTER]!r}: {!r}\n ' .format (os .environ , exc ))
110118
@@ -142,14 +150,12 @@ def _prepare_config(*args, **kwargs):
142150 continue
143151
144152 _default_config .pop (key )
145- sys .stderr .write ('Discarded config from PYTHONHUNTERCONFIG {}={!r}: Unknown option\n ' .format (
146- key , value ))
153+ sys .stderr .write ('Discarded config from PYTHONHUNTERCONFIG {}={!r}: Unknown option\n ' .format (key , value ))
147154 for position , predicate in enumerate (args ):
148155 if callable (predicate ):
149156 predicates .append (predicate )
150157 else :
151- sys .stderr .write ('Discarded config from PYTHONHUNTERCONFIG {} (position {}): Not a callable\n ' .format (
152- predicate , position ))
158+ sys .stderr .write ('Discarded config from PYTHONHUNTERCONFIG {} (position {}): Not a callable\n ' .format (predicate , position ))
153159
154160 return predicates , options
155161
@@ -176,17 +182,14 @@ def Q(*predicates, **query):
176182 raise TypeError ('Action {0!r} is not callable.' .format (a ))
177183
178184 if predicates :
179- predicates = tuple (
180- p () if inspect .isclass (p ) and issubclass (p , Action ) else p
181- for p in predicates
182- )
185+ predicates = tuple (p () if inspect .isclass (p ) and issubclass (p , Action ) else p for p in predicates )
183186 if any (isinstance (p , (CallPrinter , CodePrinter )) for p in predicates ):
184187 # the user provided an action as a filter, remove the action then to prevent double output
185188 for action in optional_actions :
186189 if action in (CallPrinter , CodePrinter ) or isinstance (action , (CallPrinter , CodePrinter )):
187190 optional_actions .remove (action )
188191 if query :
189- predicates += Query (** query ),
192+ predicates += ( Query (** query ),)
190193
191194 result = And (* predicates )
192195 else :
@@ -201,7 +204,7 @@ def Q(*predicates, **query):
201204def _merge (* predicates , ** query ):
202205 if predicates :
203206 if query :
204- predicates += Query (** query ),
207+ predicates += ( Query (** query ),)
205208 return And (* predicates )
206209 else :
207210 return Query (** query )
@@ -240,7 +243,7 @@ def And(*predicates, **kwargs):
240243 :class:`hunter.predicates.And`
241244 """
242245 if kwargs :
243- predicates += Query (** kwargs ),
246+ predicates += ( Query (** kwargs ),)
244247 return _flatten (_And , * predicates )
245248
246249
@@ -278,7 +281,7 @@ def Not(*predicates, **kwargs):
278281 :class:`hunter.predicates.Not`
279282 """
280283 if kwargs :
281- predicates += Query (** kwargs ),
284+ predicates += ( Query (** kwargs ),)
282285 if len (predicates ) > 1 :
283286 return _Not (_flatten (_And , * predicates ))
284287 else :
@@ -310,8 +313,7 @@ def From(condition=None, predicate=None, watermark=0, **kwargs):
310313 return _From (Q (** condition_kwargs ), Q (** predicate_kwargs ), watermark )
311314 else :
312315 if kwargs :
313- raise TypeError ("Unexpected arguments {}. Don't combine positional with keyword arguments." .format (
314- kwargs .keys ()))
316+ raise TypeError ("Unexpected arguments {}. Don't combine positional with keyword arguments." .format (kwargs .keys ()))
315317 return _From (condition , predicate , watermark )
316318
317319
@@ -343,9 +345,18 @@ def Backlog(*conditions, **kwargs):
343345 strip = kwargs .pop ('strip' , True )
344346 vars = kwargs .pop ('vars' , False )
345347 if not conditions and not kwargs :
346- raise TypeError ('Backlog needs at least 1 condition '
347- "(it doesn't have any effect without one besides making everything incredibly slow)." )
348- return _Backlog (_merge (* conditions , ** kwargs ), size = size , stack = stack , vars = vars , strip = strip , action = action , filter = filter )
348+ raise TypeError (
349+ 'Backlog needs at least 1 condition ' "(it doesn't have any effect without one besides making everything incredibly slow)."
350+ )
351+ return _Backlog (
352+ _merge (* conditions , ** kwargs ),
353+ size = size ,
354+ stack = stack ,
355+ vars = vars ,
356+ strip = strip ,
357+ action = action ,
358+ filter = filter ,
359+ )
349360
350361
351362def stop ():
@@ -467,11 +478,13 @@ def tracing_wrapper(*args, **kwargs):
467478 predicates .append (
468479 From (
469480 Query (kind = 'call' ),
470- Not (When (
471- Query (calls_gt = 0 , depth = 0 ) & Not (Query (kind = 'return' )),
472- Stop
473- )),
474- watermark = - 1
481+ Not (
482+ When (
483+ Query (calls_gt = 0 , depth = 0 ) & Not (Query (kind = 'return' )),
484+ Stop ,
485+ )
486+ ),
487+ watermark = - 1 ,
475488 )
476489 )
477490 local_tracer = trace (* predicates , ** trace_options )
@@ -496,8 +509,7 @@ def load_config(*args, **kwargs):
496509 else :
497510 _default_trace_args = eval ('_prepare_config({})' .format (os .environ .get ('PYTHONHUNTERCONFIG' , '' )))
498511 except Exception as exc :
499- sys .stderr .write ('Failed to load hunter config from PYTHONHUNTERCONFIG {[PYTHONHUNTERCONFIG]!r}: {!r}\n ' .format (
500- os .environ , exc ))
512+ sys .stderr .write ('Failed to load hunter config from PYTHONHUNTERCONFIG {[PYTHONHUNTERCONFIG]!r}: {!r}\n ' .format (os .environ , exc ))
501513 _default_trace_args = (), ()
502514
503515
0 commit comments