Skip to content

Commit

Permalink
Fix TypeError by explictly calling shadowed builtins.type (#762)
Browse files Browse the repository at this point in the history
  • Loading branch information
aazuspan authored Jan 4, 2024
1 parent 47c87b3 commit 5c650ef
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/dvclive/live.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import annotations
import builtins
import glob
import json
import logging
Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions tests/test_log_artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """
Expand Down Expand Up @@ -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)

0 comments on commit 5c650ef

Please sign in to comment.