Skip to content

Commit b8fdfba

Browse files
committed
Replace Text with str
Those are synonyms in Python 3.
1 parent 4590015 commit b8fdfba

File tree

3 files changed

+58
-58
lines changed

3 files changed

+58
-58
lines changed

src/dotenv/main.py

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import tempfile
77
from collections import OrderedDict
88
from 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

1212
from .parser import Binding, parse_stream
1313
from .variables import parse_variables
@@ -17,7 +17,7 @@
1717
if sys.version_info >= (3, 6):
1818
_PathLike = os.PathLike
1919
else:
20-
_PathLike = Text
20+
_PathLike = str
2121

2222

2323
def 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
3333
class 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

133133
def 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

177177
def 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

207207
def 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

250250
def 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

291291
def 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

322322
def 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

src/dotenv/parser.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import codecs
22
import re
33
from typing import (IO, Iterator, Match, NamedTuple, Optional, # noqa:F401
4-
Pattern, Sequence, Text, Tuple)
4+
Pattern, Sequence, Tuple)
55

66

7-
def make_regex(string: str, extra_flags: int = 0) -> Pattern[Text]:
7+
def make_regex(string: str, extra_flags: int = 0) -> Pattern[str]:
88
return re.compile(string, re.UNICODE | extra_flags)
99

1010

@@ -28,16 +28,16 @@ def make_regex(string: str, extra_flags: int = 0) -> Pattern[Text]:
2828
Original = NamedTuple(
2929
"Original",
3030
[
31-
("string", Text),
31+
("string", str),
3232
("line", int),
3333
],
3434
)
3535

3636
Binding = NamedTuple(
3737
"Binding",
3838
[
39-
("key", Optional[Text]),
40-
("value", Optional[Text]),
39+
("key", Optional[str]),
40+
("value", Optional[str]),
4141
("original", Original),
4242
("error", bool),
4343
],
@@ -57,7 +57,7 @@ def set(self, other: "Position") -> None:
5757
self.chars = other.chars
5858
self.line = other.line
5959

60-
def advance(self, string: Text) -> None:
60+
def advance(self, string: str) -> None:
6161
self.chars += len(string)
6262
self.line += len(re.findall(_newline, string))
6363

@@ -67,7 +67,7 @@ class Error(Exception):
6767

6868

6969
class Reader:
70-
def __init__(self, stream: IO[Text]) -> None:
70+
def __init__(self, stream: IO[str]) -> None:
7171
self.string = stream.read()
7272
self.position = Position.start()
7373
self.mark = Position.start()
@@ -84,32 +84,32 @@ def get_marked(self) -> Original:
8484
line=self.mark.line,
8585
)
8686

87-
def peek(self, count: int) -> Text:
87+
def peek(self, count: int) -> str:
8888
return self.string[self.position.chars:self.position.chars + count]
8989

90-
def read(self, count: int) -> Text:
90+
def read(self, count: int) -> str:
9191
result = self.string[self.position.chars:self.position.chars + count]
9292
if len(result) < count:
9393
raise Error("read: End of string")
9494
self.position.advance(result)
9595
return result
9696

97-
def read_regex(self, regex: Pattern[Text]) -> Sequence[Text]:
97+
def read_regex(self, regex: Pattern[str]) -> Sequence[str]:
9898
match = regex.match(self.string, self.position.chars)
9999
if match is None:
100100
raise Error("read_regex: Pattern not found")
101101
self.position.advance(self.string[match.start():match.end()])
102102
return match.groups()
103103

104104

105-
def decode_escapes(regex: Pattern[Text], string: Text) -> Text:
106-
def decode_match(match: Match[Text]) -> Text:
105+
def decode_escapes(regex: Pattern[str], string: str) -> str:
106+
def decode_match(match: Match[str]) -> str:
107107
return codecs.decode(match.group(0), 'unicode-escape') # type: ignore
108108

109109
return regex.sub(decode_match, string)
110110

111111

112-
def parse_key(reader: Reader) -> Optional[Text]:
112+
def parse_key(reader: Reader) -> Optional[str]:
113113
char = reader.peek(1)
114114
if char == "#":
115115
return None
@@ -120,12 +120,12 @@ def parse_key(reader: Reader) -> Optional[Text]:
120120
return key
121121

122122

123-
def parse_unquoted_value(reader: Reader) -> Text:
123+
def parse_unquoted_value(reader: Reader) -> str:
124124
(part,) = reader.read_regex(_unquoted_value)
125125
return re.sub(r"\s+#.*", "", part).rstrip()
126126

127127

128-
def parse_value(reader: Reader) -> Text:
128+
def parse_value(reader: Reader) -> str:
129129
char = reader.peek(1)
130130
if char == u"'":
131131
(value,) = reader.read_regex(_single_quoted_value)
@@ -155,7 +155,7 @@ def parse_binding(reader: Reader) -> Binding:
155155
reader.read_regex(_whitespace)
156156
if reader.peek(1) == "=":
157157
reader.read_regex(_equal_sign)
158-
value = parse_value(reader) # type: Optional[Text]
158+
value = parse_value(reader) # type: Optional[str]
159159
else:
160160
value = None
161161
reader.read_regex(_comment)
@@ -176,7 +176,7 @@ def parse_binding(reader: Reader) -> Binding:
176176
)
177177

178178

179-
def parse_stream(stream: IO[Text]) -> Iterator[Binding]:
179+
def parse_stream(stream: IO[str]) -> Iterator[Binding]:
180180
reader = Reader(stream)
181181
while reader.has_next():
182182
yield parse_binding(reader)

src/dotenv/variables.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import re
22
from abc import ABCMeta
3-
from typing import Iterator, Mapping, Optional, Pattern, Text
3+
from typing import Iterator, Mapping, Optional, Pattern
44

55
_posix_variable = re.compile(
66
r"""
@@ -12,7 +12,7 @@
1212
\}
1313
""",
1414
re.VERBOSE,
15-
) # type: Pattern[Text]
15+
) # type: Pattern[str]
1616

1717

1818
class Atom():
@@ -24,12 +24,12 @@ def __ne__(self, other: object) -> bool:
2424
return NotImplemented
2525
return not result
2626

27-
def resolve(self, env: Mapping[Text, Optional[Text]]) -> Text:
27+
def resolve(self, env: Mapping[str, Optional[str]]) -> str:
2828
raise NotImplementedError
2929

3030

3131
class Literal(Atom):
32-
def __init__(self, value: Text) -> None:
32+
def __init__(self, value: str) -> None:
3333
self.value = value
3434

3535
def __repr__(self) -> str:
@@ -43,12 +43,12 @@ def __eq__(self, other: object) -> bool:
4343
def __hash__(self) -> int:
4444
return hash((self.__class__, self.value))
4545

46-
def resolve(self, env: Mapping[Text, Optional[Text]]) -> Text:
46+
def resolve(self, env: Mapping[str, Optional[str]]) -> str:
4747
return self.value
4848

4949

5050
class Variable(Atom):
51-
def __init__(self, name: Text, default: Optional[Text]) -> None:
51+
def __init__(self, name: str, default: Optional[str]) -> None:
5252
self.name = name
5353
self.default = default
5454

@@ -63,13 +63,13 @@ def __eq__(self, other: object) -> bool:
6363
def __hash__(self) -> int:
6464
return hash((self.__class__, self.name, self.default))
6565

66-
def resolve(self, env: Mapping[Text, Optional[Text]]) -> Text:
66+
def resolve(self, env: Mapping[str, Optional[str]]) -> str:
6767
default = self.default if self.default is not None else ""
6868
result = env.get(self.name, default)
6969
return result if result is not None else ""
7070

7171

72-
def parse_variables(value: Text) -> Iterator[Atom]:
72+
def parse_variables(value: str) -> Iterator[Atom]:
7373
cursor = 0
7474

7575
for match in _posix_variable.finditer(value):

0 commit comments

Comments
 (0)