Skip to content

Commit

Permalink
Use contextlib.closing.
Browse files Browse the repository at this point in the history
  • Loading branch information
sarutak committed Aug 17, 2023
1 parent 3295552 commit 9024ed0
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lang/py/avro/test/gen_interop_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io
import json
import os
from contextlib import closing
from pathlib import Path
from typing import IO, TextIO

Expand Down Expand Up @@ -73,7 +74,6 @@ def generate(schema_file: TextIO, output_path: IO) -> None:
continue
base, ext = os.path.splitext(output_path.name)
Path(f"{base}_{codec}{ext}").write_bytes(data)
output_path.close()


def _parse_args() -> argparse.Namespace:
Expand All @@ -94,7 +94,8 @@ def _parse_args() -> argparse.Namespace:

def main() -> int:
args = _parse_args()
generate(args.schema_path, args.output_path)
with closing(args.output_path) as op:
generate(args.schema_path, op)
return 0


Expand Down

0 comments on commit 9024ed0

Please sign in to comment.