Skip to content

params: Python parameters file does not support type constructors #6511

@daavoo

Description

@daavoo

Bug Report

Description

When using Python parameters file, the type constructors syntax (i.e. my_dict = dict(a=1)) is not correctly parsed.

Reproduce

from pathlib import Path
from dvc.utils.serialize import load_py

Path("params.py").write_text("my_dict = dict(a=1)")

parsed_params = load_py("params.py")

# parsed_params is empty
# Raises KeyError: 'my_dict' 
assert parsed_params["my_dict"]["a"] == 1

Expected

I would expect type constructors to be correctly parsed, like the other syntaxes for constructing python built-in types. The following works as intended:

from pathlib import Path
from dvc.utils.serialize import load_py

Path("params.py").write_text("my_dict = {'a': 1}")

parsed_params = load_py("params.py")

assert parsed_params["my_dict"]["a"] == 1

Environment information

Output of dvc doctor:

$ dvc doctor
DVC version: 2.6.4+b5fe9b.mod 
---------------------------------
Platform: Python 3.9.6 on macOS-10.16-x86_64-i386-64bit
Supports:
        azure (adlfs = 2021.7.1, knack = 0.8.2, azure-identity = 1.6.0),
        gdrive (pydrive2 = 1.8.3),
        gs (gcsfs = 2021.7.0),
        hdfs (pyarrow = 5.0.0),
        webhdfs (hdfs = 2.5.8),
        http (requests = 2.26.0),
        https (requests = 2.26.0),
        s3 (s3fs = 2021.7.0, boto3 = 1.17.106),
        ssh (sshfs = 2021.7.1),
        oss (ossfs = 2021.7.5),
        webdav (webdav4 = 0.9.0),
        webdavs (webdav4 = 0.9.0)
Cache types: reflink, hardlink, symlink
Cache directory: apfs on /dev/disk1s1s1
Caches: local
Remotes: https
Workspace directory: apfs on /dev/disk1s1s1
Repo: dvc, git

Metadata

Metadata

Assignees

No one assigned

    Labels

    A: paramsRelated to dvc params

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions