2525from  platform  import  system 
2626from  subprocess  import  PIPE 
2727from  time  import  sleep 
28+ from  typing  import  cast 
2829from  urllib  import  request 
2930from  urllib .error  import  URLError 
3031
@@ -55,11 +56,11 @@ def __init__(
5556        ** kwargs ,
5657    ) ->  None :
5758        if  isinstance (log_output , str ):
58-             self .log_output  =  open (log_output , "a+" , encoding = "utf-8" )
59+             self .log_output  =  cast ( IOBase ,  open (log_output , "a+" , encoding = "utf-8" ) )
5960        elif  log_output  ==  subprocess .STDOUT :
60-             self .log_output  =  None 
61+             self .log_output  =  cast ( typing . Optional [ typing . Union [ int ,  IOBase ]],  None ) 
6162        elif  log_output  is  None  or  log_output  ==  subprocess .DEVNULL :
62-             self .log_output  =  subprocess .DEVNULL 
63+             self .log_output  =  cast ( typing . Optional [ typing . Union [ int ,  IOBase ]],  subprocess .DEVNULL ) 
6364        else :
6465            self .log_output  =  log_output 
6566
@@ -82,7 +83,7 @@ def command_line_args(self) -> typing.List[str]:
8283
8384    @property  
8485    def  path (self ) ->  str :
85-         return  self ._path 
86+         return  self ._path   or   "" 
8687
8788    @path .setter  
8889    def  path (self , value : str ) ->  None :
@@ -95,6 +96,8 @@ def start(self) -> None:
9596         - WebDriverException : Raised either when it can't start the service 
9697           or when it can't connect to the service 
9798        """ 
99+         if  self ._path  is  None :
100+             raise  WebDriverException ("Service path cannot be None." )
98101        self ._start_process (self ._path )
99102
100103        count  =  0 
@@ -201,16 +204,16 @@ def _start_process(self, path: str) -> None:
201204        try :
202205            start_info  =  None 
203206            if  system () ==  "Windows" :
204-                 start_info  =  subprocess .STARTUPINFO ()
205-                 start_info .dwFlags  =  subprocess .CREATE_NEW_CONSOLE  |  subprocess .STARTF_USESHOWWINDOW 
206-                 start_info .wShowWindow  =  subprocess .SW_HIDE 
207+                 start_info  =  subprocess .STARTUPINFO ()   # type: ignore[attr-defined] 
208+                 start_info .dwFlags  =  subprocess .CREATE_NEW_CONSOLE  |  subprocess .STARTF_USESHOWWINDOW    # type: ignore[attr-defined] 
209+                 start_info .wShowWindow  =  subprocess .SW_HIDE    # type: ignore[attr-defined] 
207210
208211            self .process  =  subprocess .Popen (
209212                cmd ,
210213                env = self .env ,
211214                close_fds = close_file_descriptors ,
212-                 stdout = self .log_output ,
213-                 stderr = self .log_output ,
215+                 stdout = cast ( typing . Optional [ typing . Union [ int ,  typing . IO [ typing . Any ]]],  self .log_output ) ,
216+                 stderr = cast ( typing . Optional [ typing . Union [ int ,  typing . IO [ typing . Any ]]],  self .log_output ) ,
214217                stdin = PIPE ,
215218                creationflags = self .creation_flags ,
216219                startupinfo = start_info ,
@@ -227,6 +230,8 @@ def _start_process(self, path: str) -> None:
227230            raise 
228231        except  OSError  as  err :
229232            if  err .errno  ==  errno .EACCES :
233+                 if  self ._path  is  None :
234+                     raise  WebDriverException ("Service path cannot be None." )
230235                raise  WebDriverException (
231236                    f"'{ os .path .basename (self ._path )}  ' executable may have wrong permissions." 
232237                ) from  err 
0 commit comments