From 4741ca7a79ec451ee5ba90ac10e33b01e9f1ff96 Mon Sep 17 00:00:00 2001 From: Anurag Singh Date: Wed, 2 Dec 2026 00:07:48 +0530 Subject: [PATCH 1/3] Replace strictyaml with PyYAML strictyaml is no longer maintained. BaseLoader keeps every scalar as a string, which matches how .pyiceberg.yaml is parsed today. --- pyiceberg/utils/config.py | 6 +++--- pyproject.toml | 2 +- tests/utils/test_config.py | 24 ++++++++++++++++++++---- uv.lock | 20 ++++---------------- 4 files changed, 28 insertions(+), 24 deletions(-) diff --git a/pyiceberg/utils/config.py b/pyiceberg/utils/config.py index 4d58365d52..0253b8b6cd 100644 --- a/pyiceberg/utils/config.py +++ b/pyiceberg/utils/config.py @@ -17,7 +17,7 @@ import logging import os -import strictyaml +import yaml from pyiceberg.typedef import UTF8, FrozenDict, RecursiveDict from pyiceberg.types import strtobool @@ -79,9 +79,9 @@ def _load_yaml(directory: str | None) -> RecursiveDict | None: if os.path.isfile(path): with open(path, encoding=UTF8) as f: yml_str = f.read() - file_config = strictyaml.load(yml_str).data + file_config = yaml.load(yml_str, Loader=yaml.BaseLoader) if not isinstance(file_config, dict): - # An empty or comment-only document parses as a string + # An empty or comment-only document parses as None return None file_config_lowercase = _lowercase_dictionary_keys(file_config) return file_config_lowercase diff --git a/pyproject.toml b/pyproject.toml index dc5f7df558..ea79200858 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,7 +35,7 @@ dependencies = [ "requests>=2.20.0", "click>=7.1.1", "rich>=10.11.0", - "strictyaml>=1.7.0", # CVE-2020-14343 was fixed in 5.4. + "pyyaml>=6.0", "pydantic>=2.0,<3.0,!=2.4.0,!=2.4.1,!=2.12.0,!=2.12.1", # 2.4.0, 2.4.1, 2.12.0, 2.12.1 has a critical bug "fsspec>=2023.1.0", "pyparsing>=3.1.0", diff --git a/tests/utils/test_config.py b/tests/utils/test_config.py index 17b495f929..da031cb332 100644 --- a/tests/utils/test_config.py +++ b/tests/utils/test_config.py @@ -19,7 +19,7 @@ from unittest import mock import pytest -from strictyaml import as_document +import yaml from pyiceberg.typedef import UTF8, RecursiveDict from pyiceberg.utils.config import Config, _lowercase_dictionary_keys, merge_config @@ -67,7 +67,7 @@ def test_list_all_known_catalogs() -> None: def test_from_configuration_files(tmp_path_factory: pytest.TempPathFactory) -> None: config_path = str(tmp_path_factory.mktemp("config")) with open(f"{config_path}/.pyiceberg.yaml", "w", encoding=UTF8) as file: - yaml_str = as_document({"catalog": {"production": {"uri": "https://service.io/api"}}}).as_yaml() + yaml_str = yaml.safe_dump({"catalog": {"production": {"uri": "https://service.io/api"}}}) file.write(yaml_str) os.environ["PYICEBERG_HOME"] = config_path @@ -112,7 +112,7 @@ def test_merge_config_lhs_wins_when_rhs_is_none() -> None: def test_from_configuration_files_get_typed_value(tmp_path_factory: pytest.TempPathFactory) -> None: config_path = str(tmp_path_factory.mktemp("config")) with open(f"{config_path}/.pyiceberg.yaml", "w", encoding=UTF8) as file: - yaml_str = as_document({"max-workers": "4", "legacy-current-snapshot-id": "True"}).as_yaml() + yaml_str = yaml.safe_dump({"max-workers": "4", "legacy-current-snapshot-id": "True"}) file.write(yaml_str) os.environ["PYICEBERG_HOME"] = config_path @@ -126,6 +126,22 @@ def test_from_configuration_files_get_typed_value(tmp_path_factory: pytest.TempP assert Config().get_int("max-workers") == 4 +def test_from_configuration_files_keeps_scalars_as_strings( + monkeypatch: pytest.MonkeyPatch, tmp_path_factory: pytest.TempPathFactory +) -> None: + config_path = str(tmp_path_factory.mktemp("config")) + with open(f"{config_path}/.pyiceberg.yaml", "w", encoding=UTF8) as file: + file.write("max-workers: 4\nlegacy-current-snapshot-id: yes\nsample-rate: 1.0\n") + + monkeypatch.setenv("PYICEBERG_HOME", config_path) + config = Config() + assert config.config["max-workers"] == "4" + assert config.config["legacy-current-snapshot-id"] == "yes" + assert config.config["sample-rate"] == "1.0" + assert config.get_int("max-workers") == 4 + assert config.get_bool("legacy-current-snapshot-id") + + @pytest.mark.parametrize( "config_setup, expected_result", [ @@ -182,7 +198,7 @@ def create_config_file(path: str, uri: str | None) -> None: config_file_path = os.path.join(path, ".pyiceberg.yaml") content = {"catalog": {"default": {"uri": uri}}} with open(config_file_path, "w", encoding="utf-8") as file: - yaml_str = as_document(content).as_yaml() + yaml_str = yaml.safe_dump(content) file.write(yaml_str) # Create temporary directories for PYICEBERG_HOME, home (~), and cwd diff --git a/uv.lock b/uv.lock index 0b48446ccf..617ca17327 100644 --- a/uv.lock +++ b/uv.lock @@ -506,8 +506,8 @@ resolution-markers = [ "python_full_version >= '3.11.5' and python_full_version < '3.12' and sys_platform != 'emscripten' and sys_platform != 'win32'", ] dependencies = [ - { name = "soupsieve", marker = "python_full_version >= '3.11.5'" }, - { name = "typing-extensions", marker = "python_full_version >= '3.11.5'" }, + { name = "soupsieve" }, + { name = "typing-extensions" }, ] sdist = { url = "https://files.pythonhosted.org/packages/43/65/318323f98dbee45d42dff61d8f047181bc6f2268a9068cfad035a46be5af/beautifulsoup4-4.15.0.tar.gz", hash = "sha256:288e3ca7d54b06f2ac191970bc275c1939cb46d450b255bf6718b04aa37ab4f7", size = 632571, upload-time = "2026-06-07T16:44:20.453Z" } wheels = [ @@ -4440,9 +4440,9 @@ dependencies = [ { name = "pydantic" }, { name = "pyparsing" }, { name = "pyroaring" }, + { name = "pyyaml" }, { name = "requests" }, { name = "rich" }, - { name = "strictyaml" }, { name = "tenacity" }, { name = "zstandard", marker = "python_full_version < '3.14'" }, ] @@ -4614,13 +4614,13 @@ requires-dist = [ { name = "pyparsing", specifier = ">=3.1.0" }, { name = "pyroaring", specifier = ">=1.1.0" }, { name = "python-snappy", marker = "extra == 'snappy'", specifier = ">=0.6.0" }, + { name = "pyyaml", specifier = ">=6.0" }, { name = "ray", marker = "extra == 'ray'", specifier = ">=2.10.0" }, { name = "requests", specifier = ">=2.20.0" }, { name = "rich", specifier = ">=10.11.0" }, { name = "s3fs", marker = "extra == 's3fs'", specifier = ">=2023.1.0" }, { name = "sqlalchemy", marker = "extra == 'sql-postgres'", specifier = ">=2.0.18,<3" }, { name = "sqlalchemy", marker = "extra == 'sql-sqlite'", specifier = ">=2.0.18,<3" }, - { name = "strictyaml", specifier = ">=1.7.0" }, { name = "tenacity", specifier = ">=8.2.3" }, { name = "thrift", marker = "extra == 'hive'", specifier = ">=0.13.0" }, { name = "thrift", marker = "extra == 'hive-kerberos'", specifier = ">=0.13.0" }, @@ -5774,18 +5774,6 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/f1/7b/ce1eafaf1a76852e2ec9b22edecf1daa58175c090266e9f6c64afcd81d91/stack_data-0.6.3-py3-none-any.whl", hash = "sha256:d5558e0c25a4cb0853cddad3d77da9891a08cb85dd9f9f91b9f8cd66e511e695", size = 24521, upload-time = "2023-09-30T13:58:03.53Z" }, ] -[[package]] -name = "strictyaml" -version = "1.7.3" -source = { registry = "https://pypi.org/simple" } -dependencies = [ - { name = "python-dateutil" }, -] -sdist = { url = "https://files.pythonhosted.org/packages/b3/08/efd28d49162ce89c2ad61a88bd80e11fb77bc9f6c145402589112d38f8af/strictyaml-1.7.3.tar.gz", hash = "sha256:22f854a5fcab42b5ddba8030a0e4be51ca89af0267961c8d6cfa86395586c407", size = 115206, upload-time = "2023-03-10T12:50:27.062Z" } -wheels = [ - { url = "https://files.pythonhosted.org/packages/96/7c/a81ef5ef10978dd073a854e0fa93b5d8021d0594b639cc8f6453c3c78a1d/strictyaml-1.7.3-py3-none-any.whl", hash = "sha256:fb5c8a4edb43bebb765959e420f9b3978d7f1af88c80606c03fb420888f5d1c7", size = 123917, upload-time = "2023-03-10T12:50:17.242Z" }, -] - [[package]] name = "sympy" version = "1.14.0" From 1b1a17a7966d59a6aacfbbf75a69a62066b8a610 Mon Sep 17 00:00:00 2001 From: Anurag Singh Date: Wed, 2 Dec 2026 01:28:57 +0530 Subject: [PATCH 2/3] Add PyYAML type stubs for mypy The yaml import needs types-PyYAML in the pre-commit mypy environment. --- .pre-commit-config.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f0dedd0804..b128f2d972 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -47,6 +47,7 @@ repos: - types-pytest-lazy-fixture - types-pytz - types-requests + - types-PyYAML - repo: https://github.com/igorshubovych/markdownlint-cli rev: v0.45.0 hooks: From 946c0e2b1fed81e408f0333b7dd5702f07bf74ca Mon Sep 17 00:00:00 2001 From: Kevin Liu Date: Tue, 1 Dec 2026 12:12:26 -0800 Subject: [PATCH 3/3] Prefer CBaseLoader and expand scalar preservation test - Use yaml.CBaseLoader with yaml.BaseLoader fallback when loading .pyiceberg.yaml since Config() is instantiated across runtime paths. - Cover NO, null, ~, empty values, and ISO dates in scalar-preservation config tests. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- pyiceberg/utils/config.py | 7 ++++++- tests/utils/test_config.py | 16 +++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/pyiceberg/utils/config.py b/pyiceberg/utils/config.py index 0253b8b6cd..ebbbc16adb 100644 --- a/pyiceberg/utils/config.py +++ b/pyiceberg/utils/config.py @@ -19,6 +19,11 @@ import yaml +try: + from yaml import CBaseLoader as _YamlLoader +except ImportError: + from yaml import BaseLoader as _YamlLoader # type: ignore[assignment] + from pyiceberg.typedef import UTF8, FrozenDict, RecursiveDict from pyiceberg.types import strtobool @@ -79,7 +84,7 @@ def _load_yaml(directory: str | None) -> RecursiveDict | None: if os.path.isfile(path): with open(path, encoding=UTF8) as f: yml_str = f.read() - file_config = yaml.load(yml_str, Loader=yaml.BaseLoader) + file_config = yaml.load(yml_str, Loader=_YamlLoader) if not isinstance(file_config, dict): # An empty or comment-only document parses as None return None diff --git a/tests/utils/test_config.py b/tests/utils/test_config.py index da031cb332..ac51468da7 100644 --- a/tests/utils/test_config.py +++ b/tests/utils/test_config.py @@ -131,13 +131,27 @@ def test_from_configuration_files_keeps_scalars_as_strings( ) -> None: config_path = str(tmp_path_factory.mktemp("config")) with open(f"{config_path}/.pyiceberg.yaml", "w", encoding=UTF8) as file: - file.write("max-workers: 4\nlegacy-current-snapshot-id: yes\nsample-rate: 1.0\n") + file.write( + "max-workers: 4\n" + "legacy-current-snapshot-id: yes\n" + "sample-rate: 1.0\n" + "country: NO\n" + "null-val: null\n" + "tilde-val: ~\n" + "empty-val:\n" + "date-val: 2024-01-01\n" + ) monkeypatch.setenv("PYICEBERG_HOME", config_path) config = Config() assert config.config["max-workers"] == "4" assert config.config["legacy-current-snapshot-id"] == "yes" assert config.config["sample-rate"] == "1.0" + assert config.config["country"] == "NO" + assert config.config["null-val"] == "null" + assert config.config["tilde-val"] == "~" + assert config.config["empty-val"] == "" + assert config.config["date-val"] == "2024-01-01" assert config.get_int("max-workers") == 4 assert config.get_bool("legacy-current-snapshot-id")