44# Copyright (c) 2023 Tiago Coutinho
55# Distributed under the GPLv3 license. See LICENSE for more info.
66
7+ import typing
78import functools
89import importlib
910import os
11+ import io
1012import select
1113
14+ StrOrBytesPath : typing .TypeAlias = str | bytes | os .PathLike [str ] | os .PathLike [bytes ]
1215
13- def fopen (path , rw = False , binary = True , blocking = False , close_on_exec = True ):
16+ FileDescriptorOrPath : typing .TypeAlias = int | StrOrBytesPath
17+
18+
19+ def fopen (
20+ path : StrOrBytesPath ,
21+ rw : bool = False ,
22+ binary : bool = True ,
23+ blocking : bool = False ,
24+ close_on_exec : bool = True
25+ ) -> io .FileIO | io .TextIOWrapper :
1426 def opener (path , flags ):
1527 if not blocking :
1628 flags |= os .O_NONBLOCK
@@ -39,7 +51,7 @@ class IO:
3951
4052
4153class GeventModule :
42- def __init__ (self , name ):
54+ def __init__ (self , name : str ):
4355 self .name = name
4456 self ._module = None
4557
@@ -49,15 +61,15 @@ def module(self):
4961 self ._module = importlib .import_module (f"gevent.{ self .name } " )
5062 return self ._module
5163
52- def __getattr__ (self , name ):
64+ def __getattr__ (self , name : str ):
5365 attr = getattr (self .module , name )
5466 setattr (self , name , attr )
5567 return attr
5668
5769
5870class GeventIO :
5971 @staticmethod
60- def open (path , rw = False , blocking = False ):
72+ def open (path : FileDescriptorOrPath , rw : bool = False , blocking : bool = False ):
6173 mode = "rb+" if rw else "rb"
6274 import gevent .fileobject
6375
0 commit comments