From ca3ffb1dbbba54e85c9b8bcd9f628e8079005fb9 Mon Sep 17 00:00:00 2001 From: azuspan607 Date: Thu, 4 Jan 2024 11:27:53 -0800 Subject: [PATCH] Fix `TypeError` by explictly calling shadowed `builtins.type` --- src/dvclive/live.py | 3 ++- tests/test_log_artifact.py | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/dvclive/live.py b/src/dvclive/live.py index e230795e..ce8d5357 100644 --- a/src/dvclive/live.py +++ b/src/dvclive/live.py @@ -1,4 +1,5 @@ from __future__ import annotations +import builtins import glob import json import logging @@ -491,7 +492,7 @@ def log_artifact( ): """Tracks a local file or directory with DVC""" if not isinstance(path, (str, Path)): - raise InvalidDataTypeError(path, type(path)) + raise InvalidDataTypeError(path, builtins.type(path)) if self._dvc_repo is not None: from gto.constants import assert_name_is_valid diff --git a/tests/test_log_artifact.py b/tests/test_log_artifact.py index 605e05ee..987ccaa0 100644 --- a/tests/test_log_artifact.py +++ b/tests/test_log_artifact.py @@ -5,6 +5,7 @@ from dvc.exceptions import DvcException from dvclive import Live +from dvclive.error import InvalidDataTypeError from dvclive.serialize import load_yaml dvcyaml = """ @@ -295,3 +296,11 @@ def test_log_artifact_no_repo(tmp_dir, mocker): logger.warning.assert_called_with( "A DVC repo is required to log artifacts. Skipping `log_artifact(data)`." ) + + +@pytest.mark.parametrize("invalid_path", [None, 1.0, True, [], {}], ids=type) +def test_log_artifact_invalid_path_type(invalid_path, tmp_dir): + live = Live(save_dvc_exp=False) + expected_error_msg = f"not supported type {type(invalid_path)}" + with pytest.raises(InvalidDataTypeError, match=expected_error_msg): + live.log_artifact(path=invalid_path)