diff --git a/telethon_generator/docswriter.py b/telethon_generator/docswriter.py index 6d37d729..482fe3bf 100644 --- a/telethon_generator/docswriter.py +++ b/telethon_generator/docswriter.py @@ -288,7 +288,7 @@ class DocsWriter: def __enter__(self): # Sanity check self.filename.parent.mkdir(parents=True, exist_ok=True) - self.handle = open(self.filename, 'w', encoding='utf-8') + self.handle = self.filename.open('w', encoding='utf-8') return self def __exit__(self, exc_type, exc_val, exc_tb): diff --git a/telethon_generator/generators/docs.py b/telethon_generator/generators/docs.py index 42a76a3f..b013f290 100755 --- a/telethon_generator/generators/docs.py +++ b/telethon_generator/generators/docs.py @@ -196,7 +196,7 @@ def _get_description(arg): def _copy_replace(src, dst, replacements): """Copies the src file into dst applying the replacements dict""" - with open(src, 'r') as infile, open(dst, 'w') as outfile: + with src.open() as infile, dst.open('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/tlobject/parser.py b/telethon_generator/parsers/tlobject/parser.py index 2134eef8..b3caff2a 100644 --- a/telethon_generator/parsers/tlobject/parser.py +++ b/telethon_generator/parsers/tlobject/parser.py @@ -137,7 +137,7 @@ def parse_tl(file_path, layer, methods=None, ignored_ids=CORE_TYPES): 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, 'r', encoding='utf-8') as file: + with file_path.open('r') as file: for line in file: match = layer_regex.match(line) if match: