From c548b0792d6233f4b009f83247f8e38a5d859f06 Mon Sep 17 00:00:00 2001 From: Alexander Schepanovski Date: Fri, 10 Jan 2020 20:59:17 +0700 Subject: [PATCH] summon: fix open() shadowing --- dvc/api.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/dvc/api.py b/dvc/api.py index 7ba7528e29..22dccb5e11 100644 --- a/dvc/api.py +++ b/dvc/api.py @@ -1,3 +1,4 @@ +from builtins import open as builtin_open import importlib import os import sys @@ -11,7 +12,7 @@ from voluptuous import Schema, Required, Invalid from dvc.repo import Repo -from dvc.exceptions import DvcException, FileMissingError +from dvc.exceptions import DvcException from dvc.external_repo import external_repo @@ -123,8 +124,8 @@ def _get_object_from_summon_file(name, path): and return its description. """ try: - with open(path, "r") as fobj: - content = SUMMON_SCHEMA(ruamel.yaml.safe_load(fobj.read())) + with builtin_open(path, "r") as fd: + content = SUMMON_SCHEMA(ruamel.yaml.safe_load(fd.read())) objects = [x for x in content["objects"] if x["name"] == name] if not objects: @@ -136,8 +137,8 @@ def _get_object_from_summon_file(name, path): return objects[0] - except FileMissingError: - raise SummonError("Summon file not found") + except FileNotFoundError as exc: + raise SummonError("Summon file not found") from exc except ruamel.yaml.YAMLError as exc: raise SummonError("Failed to parse summon file") from exc except Invalid as exc: