66import tempfile
77from collections import OrderedDict
88from contextlib import contextmanager
9- from typing import (IO , Dict , Iterable , Iterator , Mapping , Optional , Text ,
10- Tuple , Union )
9+ from typing import (IO , Dict , Iterable , Iterator , Mapping , Optional , Tuple ,
10+ Union )
1111
1212from .parser import Binding , parse_stream
1313from .variables import parse_variables
1717if sys .version_info >= (3 , 6 ):
1818 _PathLike = os .PathLike
1919else :
20- _PathLike = Text
20+ _PathLike = str
2121
2222
2323def with_warn_for_invalid_lines (mappings : Iterator [Binding ]) -> Iterator [Binding ]:
@@ -33,21 +33,21 @@ def with_warn_for_invalid_lines(mappings: Iterator[Binding]) -> Iterator[Binding
3333class DotEnv ():
3434 def __init__ (
3535 self ,
36- dotenv_path : Union [Text , _PathLike , io .StringIO ],
36+ dotenv_path : Union [str , _PathLike , io .StringIO ],
3737 verbose : bool = False ,
38- encoding : Union [None , Text ] = None ,
38+ encoding : Union [None , str ] = None ,
3939 interpolate : bool = True ,
4040 override : bool = True ,
4141 ) -> None :
42- self .dotenv_path = dotenv_path # type: Union[Text ,_PathLike, io.StringIO]
43- self ._dict = None # type: Optional[Dict[Text , Optional[Text ]]]
42+ self .dotenv_path = dotenv_path # type: Union[str ,_PathLike, io.StringIO]
43+ self ._dict = None # type: Optional[Dict[str , Optional[str ]]]
4444 self .verbose = verbose # type: bool
45- self .encoding = encoding # type: Union[None, Text ]
45+ self .encoding = encoding # type: Union[None, str ]
4646 self .interpolate = interpolate # type: bool
4747 self .override = override # type: bool
4848
4949 @contextmanager
50- def _get_stream (self ) -> Iterator [IO [Text ]]:
50+ def _get_stream (self ) -> Iterator [IO [str ]]:
5151 if isinstance (self .dotenv_path , io .StringIO ):
5252 yield self .dotenv_path
5353 elif os .path .isfile (self .dotenv_path ):
@@ -58,7 +58,7 @@ def _get_stream(self) -> Iterator[IO[Text]]:
5858 logger .info ("Python-dotenv could not find configuration file %s." , self .dotenv_path or '.env' )
5959 yield io .StringIO ('' )
6060
61- def dict (self ) -> Dict [Text , Optional [Text ]]:
61+ def dict (self ) -> Dict [str , Optional [str ]]:
6262 """Return dotenv as dict"""
6363 if self ._dict :
6464 return self ._dict
@@ -72,7 +72,7 @@ def dict(self) -> Dict[Text, Optional[Text]]:
7272
7373 return self ._dict
7474
75- def parse (self ) -> Iterator [Tuple [Text , Optional [Text ]]]:
75+ def parse (self ) -> Iterator [Tuple [str , Optional [str ]]]:
7676 with self ._get_stream () as stream :
7777 for mapping in with_warn_for_invalid_lines (parse_stream (stream )):
7878 if mapping .key is not None :
@@ -90,7 +90,7 @@ def set_as_environment_variables(self) -> bool:
9090
9191 return True
9292
93- def get (self , key : Text ) -> Optional [Text ]:
93+ def get (self , key : str ) -> Optional [str ]:
9494 """
9595 """
9696 data = self .dict ()
@@ -104,7 +104,7 @@ def get(self, key: Text) -> Optional[Text]:
104104 return None
105105
106106
107- def get_key (dotenv_path : Union [Text , _PathLike ], key_to_get : Text ) -> Optional [Text ]:
107+ def get_key (dotenv_path : Union [str , _PathLike ], key_to_get : str ) -> Optional [str ]:
108108 """
109109 Gets the value of a given key from the given .env
110110
@@ -114,7 +114,7 @@ def get_key(dotenv_path: Union[Text, _PathLike], key_to_get: Text) -> Optional[T
114114
115115
116116@contextmanager
117- def rewrite (path : _PathLike ) -> Iterator [Tuple [IO [Text ], IO [Text ]]]:
117+ def rewrite (path : _PathLike ) -> Iterator [Tuple [IO [str ], IO [str ]]]:
118118 try :
119119 if not os .path .isfile (path ):
120120 with io .open (path , "w+" ) as source :
@@ -132,11 +132,11 @@ def rewrite(path: _PathLike) -> Iterator[Tuple[IO[Text], IO[Text]]]:
132132
133133def set_key (
134134 dotenv_path : _PathLike ,
135- key_to_set : Text ,
136- value_to_set : Text ,
137- quote_mode : Text = "always" ,
135+ key_to_set : str ,
136+ value_to_set : str ,
137+ quote_mode : str = "always" ,
138138 export : bool = False ,
139- ) -> Tuple [Optional [bool ], Text , Text ]:
139+ ) -> Tuple [Optional [bool ], str , str ]:
140140 """
141141 Adds or Updates a key/value to the given .env
142142
@@ -176,9 +176,9 @@ def set_key(
176176
177177def unset_key (
178178 dotenv_path : _PathLike ,
179- key_to_unset : Text ,
180- quote_mode : Text = "always" ,
181- ) -> Tuple [Optional [bool ], Text ]:
179+ key_to_unset : str ,
180+ quote_mode : str = "always" ,
181+ ) -> Tuple [Optional [bool ], str ]:
182182 """
183183 Removes a given key from the given .env
184184
@@ -205,17 +205,17 @@ def unset_key(
205205
206206
207207def resolve_variables (
208- values : Iterable [Tuple [Text , Optional [Text ]]],
208+ values : Iterable [Tuple [str , Optional [str ]]],
209209 override : bool ,
210- ) -> Mapping [Text , Optional [Text ]]:
211- new_values = {} # type: Dict[Text , Optional[Text ]]
210+ ) -> Mapping [str , Optional [str ]]:
211+ new_values = {} # type: Dict[str , Optional[str ]]
212212
213213 for (name , value ) in values :
214214 if value is None :
215215 result = None
216216 else :
217217 atoms = parse_variables (value )
218- env = {} # type: Dict[Text , Optional[Text ]]
218+ env = {} # type: Dict[str , Optional[str ]]
219219 if override :
220220 env .update (os .environ ) # type: ignore
221221 env .update (new_values )
@@ -229,7 +229,7 @@ def resolve_variables(
229229 return new_values
230230
231231
232- def _walk_to_root (path : Text ) -> Iterator [Text ]:
232+ def _walk_to_root (path : str ) -> Iterator [str ]:
233233 """
234234 Yield directories starting from the given directory up to the root
235235 """
@@ -248,10 +248,10 @@ def _walk_to_root(path: Text) -> Iterator[Text]:
248248
249249
250250def find_dotenv (
251- filename : Text = '.env' ,
251+ filename : str = '.env' ,
252252 raise_error_if_not_found : bool = False ,
253253 usecwd : bool = False ,
254- ) -> Text :
254+ ) -> str :
255255 """
256256 Search in increasingly higher folders for the given file
257257
@@ -289,12 +289,12 @@ def _is_interactive():
289289
290290
291291def load_dotenv (
292- dotenv_path : Union [Text , _PathLike , None ] = None ,
292+ dotenv_path : Union [str , _PathLike , None ] = None ,
293293 stream : Optional [io .StringIO ] = None ,
294294 verbose : bool = False ,
295295 override : bool = False ,
296296 interpolate : bool = True ,
297- encoding : Optional [Text ] = "utf-8" ,
297+ encoding : Optional [str ] = "utf-8" ,
298298) -> bool :
299299 """Parse a .env file and then load all the variables found as environment variables.
300300
@@ -320,12 +320,12 @@ def load_dotenv(
320320
321321
322322def dotenv_values (
323- dotenv_path : Union [Text , _PathLike , None ] = None ,
323+ dotenv_path : Union [str , _PathLike , None ] = None ,
324324 stream : Optional [io .StringIO ] = None ,
325325 verbose : bool = False ,
326326 interpolate : bool = True ,
327- encoding : Optional [Text ] = "utf-8" ,
328- ) -> Dict [Text , Optional [Text ]]:
327+ encoding : Optional [str ] = "utf-8" ,
328+ ) -> Dict [str , Optional [str ]]:
329329 """
330330 Parse a .env file and return its content as a dict.
331331
0 commit comments