Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TypeError by explictly calling shadowed builtins.type #762

Merged
merged 1 commit into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading