diff --git a/readthedocs/conf.py b/readthedocs/conf.py
index 6c8ed0d2..07fae89b 100644
--- a/readthedocs/conf.py
+++ b/readthedocs/conf.py
@@ -68,7 +68,7 @@ author = 'Lonami'
# built documents.
#
# The short X.Y version.
-with open(os.path.join(root, 'telethon', 'version.py')) as f:
+with open(os.path.join(root, 'telethon', 'version.py'), 'r') as f:
version = re.search(r"^__version__\s+=\s+'(.*)'$",
f.read(), flags=re.MULTILINE).group(1)
diff --git a/setup.py b/setup.py
index 43cb66e2..8ac426f5 100755
--- a/setup.py
+++ b/setup.py
@@ -60,7 +60,8 @@ def generate(which):
from telethon_generator.generators import\
generate_errors, generate_tlobjects, generate_docs, clean_tlobjects
- with open(INVALID_BM_IN) as f:
+ # Older Python versions open the file as bytes instead (3.4.2)
+ with open(INVALID_BM_IN, 'r') as f:
invalid_bot_methods = set(json.load(f))
layer = find_layer(TLOBJECT_IN_TL)
@@ -176,10 +177,10 @@ def main():
generate(['tl', 'errors'])
# Get the long description from the README file
- with open('README.rst', encoding='utf-8') as f:
+ with open('README.rst', 'r', encoding='utf-8') as f:
long_description = f.read()
- with open('telethon/version.py', encoding='utf-8') as f:
+ with open('telethon/version.py', 'r', encoding='utf-8') as f:
version = re.search(r"^__version__\s*=\s*'(.*)'.*$",
f.read(), flags=re.MULTILINE).group(1)
setup(
diff --git a/telethon/sessions/sqlite.py b/telethon/sessions/sqlite.py
index cc4bd879..4f6967aa 100644
--- a/telethon/sessions/sqlite.py
+++ b/telethon/sessions/sqlite.py
@@ -119,7 +119,7 @@ class SQLiteSession(MemorySession):
def _check_migrate_json(self):
if file_exists(self.filename):
try:
- with open(self.filename, encoding='utf-8') as f:
+ with open(self.filename, 'r', encoding='utf-8') as f:
data = json.load(f)
self.delete() # Delete JSON file to create database
diff --git a/telethon_generator/generators/docs.py b/telethon_generator/generators/docs.py
index 2d51c326..98d10b73 100755
--- a/telethon_generator/generators/docs.py
+++ b/telethon_generator/generators/docs.py
@@ -68,7 +68,7 @@ def _get_relative_path(destination, relative_to, folder=False):
def _find_title(html_file):
"""Finds the
for the given HTML file, or (Unknown)."""
- with open(html_file) as fp:
+ with open(html_file, 'r') as fp:
for line in fp:
if '' in line:
# + 7 to skip len('')
@@ -221,7 +221,7 @@ def _get_description(arg):
def _copy_replace(src, dst, replacements):
"""Copies the src file into dst applying the replacements dict"""
- with open(src) as infile, open(dst, 'w') as outfile:
+ with open(src, 'r') as infile, open(dst, 'w') as outfile:
outfile.write(re.sub(
'|'.join(re.escape(k) for k in replacements),
lambda m: str(replacements[m.group(0)]),
diff --git a/telethon_generator/parsers/errors.py b/telethon_generator/parsers/errors.py
index 8f8ac36c..5ceedb3e 100644
--- a/telethon_generator/parsers/errors.py
+++ b/telethon_generator/parsers/errors.py
@@ -90,7 +90,7 @@ def parse_errors(json_file, descriptions_file):
The method yields `Error` instances as a result.
"""
- with open(json_file, encoding='utf-8') as f:
+ with open(json_file, 'r', encoding='utf-8') as f:
data = json.load(f)
errors = defaultdict(set)
@@ -124,7 +124,7 @@ def parse_errors(json_file, descriptions_file):
# Prefer the descriptions that are related with Telethon way of coding
# to those that PWRTelegram's API provides.
telethon_descriptions = {}
- with open(descriptions_file, encoding='utf-8') as f:
+ with open(descriptions_file, 'r', encoding='utf-8') as f:
for line in f:
line = line.strip()
if line and not line.startswith('#'):
diff --git a/telethon_generator/parsers/tlobject.py b/telethon_generator/parsers/tlobject.py
index 5224355c..eb8bbdd9 100644
--- a/telethon_generator/parsers/tlobject.py
+++ b/telethon_generator/parsers/tlobject.py
@@ -278,7 +278,7 @@ def parse_tl(file_path, layer, invalid_bot_methods=None):
if invalid_bot_methods is None:
invalid_bot_methods = set()
- with open(file_path, encoding='utf-8') as file:
+ with open(file_path, 'r', encoding='utf-8') as file:
is_function = False
for line in file:
comment_index = line.find('//')
@@ -307,7 +307,7 @@ def parse_tl(file_path, layer, invalid_bot_methods=None):
def find_layer(file_path):
"""Finds the layer used on the specified scheme.tl file."""
layer_regex = re.compile(r'^//\s*LAYER\s*(\d+)$')
- with open(file_path, encoding='utf-8') as file:
+ with open(file_path, 'r', encoding='utf-8') as file:
for line in file:
match = layer_regex.match(line)
if match: