@@ -51,6 +51,10 @@ def _eh_sigspec_invoke_compat(method, argc_legacy, *args):
5151 # Assume new signature (2.x)
5252 return method (* args )
5353
54+ def _eh_sigspec_ev_read_17 (ev_read ):
55+ """Helper function to check whether ev_read has the old 1.7 signature."""
56+ return len (getfullargspec (ev_read )[0 ]) == 2
57+
5458
5559class WorkerException (Exception ):
5660 """Generic worker exception."""
@@ -252,19 +256,18 @@ def _on_node_msgline(self, node, msg, sname):
252256 if sname == self .SNAME_STDERR :
253257 self .current_errmsg = msg
254258 if self .eh is not None :
255- # check for deprecated ev_error (< 1.8 )
256- if hasattr (self .eh , 'ev_error' ):
259+ # call old ev_error for compat (default is no-op )
260+ if hasattr (self .eh , 'ev_error' ): # missing in 1.8.0!
257261 self .eh .ev_error (self )
258- else :
259- # ev_read: ignore old signature (< 1.8)
260- if len (getfullargspec (self .eh .ev_read )[0 ]) != 2 :
261- ### FUTURE (2.x) ###
262- self .eh .ev_read (self , node , sname , msg )
262+ # /!\ NOT elif
263+ if not _eh_sigspec_ev_read_17 (self .eh .ev_read ):
264+ ### FUTURE (2.x) ###
265+ self .eh .ev_read (self , node , sname , msg )
263266 else :
264267 self .current_msg = msg
265268 if self .eh is not None :
266269 # ev_read: check for old signature first (< 1.8)
267- if len ( getfullargspec ( self .eh .ev_read )[ 0 ]) == 2 :
270+ if _eh_sigspec_ev_read_17 ( self .eh .ev_read ):
268271 self .eh .ev_read (self )
269272 else :
270273 ### FUTURE (2.x) ###
@@ -574,20 +577,18 @@ def _on_msgline(self, key, msg, sname):
574577 if sname == 'stderr' :
575578 self .current_errmsg = msg
576579 if self .eh is not None :
577- # this part is tricky to support backward compatibility...
578- # check for deprecated ev_error (< 1.8)
579- if hasattr (self .eh , 'ev_error' ):
580+ # call old ev_error for compat (default is no-op)
581+ if hasattr (self .eh , 'ev_error' ): # missing in 1.8.0!
580582 self .eh .ev_error (self )
581- else :
582- # ev_read: ignore old signature (< 1.8)
583- if len (getfullargspec (self .eh .ev_read )[0 ]) != 2 :
584- ### FUTURE (2.x) ###
585- self .eh .ev_read (self , key , sname , msg )
583+ # /!\ NOT elif
584+ if not _eh_sigspec_ev_read_17 (self .eh .ev_read ):
585+ ### FUTURE (2.x) ###
586+ self .eh .ev_read (self , key , sname , msg )
586587 else :
587588 self .current_msg = msg
588589 if self .eh is not None :
589590 # ev_read: check for old signature first (< 1.8)
590- if len ( getfullargspec ( self .eh .ev_read )[ 0 ]) == 2 :
591+ if _eh_sigspec_ev_read_17 ( self .eh .ev_read ):
591592 self .eh .ev_read (self )
592593 else :
593594 ### FUTURE (2.x) ###
@@ -598,6 +599,7 @@ def _on_timeout(self, key):
598599 self .task ._timeout_add (self , key )
599600
600601 # trigger timeout event (deprecated in 1.8+)
602+ # also use hasattr check because ev_timeout was missing in 1.8.0
601603 if self .eh and hasattr (self .eh , 'ev_timeout' ):
602604 self .eh .ev_timeout (self )
603605
0 commit comments