|
| 1 | +From ed7e24bdbf68c3b9f979fd5bdb46f6b6c5472549 Mon Sep 17 00:00:00 2001 |
| 2 | +From: akhila-guruju <v-guakhila@microsoft.com> |
| 3 | +Date: Tue, 12 May 2026 11:59:39 +0000 |
| 4 | +Subject: [PATCH] Upstream fix for ptests |
| 5 | + |
| 6 | +Upstream Patch reference: https://github.com/omry/omegaconf/commit/a656e85e44795d471c812d9f9c326967465cf788.patch |
| 7 | +PR: https://github.com/omry/omegaconf/pull/1225 |
| 8 | + |
| 9 | +Modified to apply to Azure Linux. |
| 10 | +Only first 2 commit changes are relevant to the ptests. |
| 11 | +Combined commit changes: https://github.com/omry/omegaconf/pull/1225/changes/BASE..8cb50f64ea58c217f908d3f65cb09c0707633234 |
| 12 | +--- |
| 13 | + pydevd_plugins/__init__.py | 7 ++-- |
| 14 | + pydevd_plugins/extensions/__init__.py | 7 ++-- |
| 15 | + tests/test_nodes.py | 50 +++++++++++++++++++++++++-- |
| 16 | + 3 files changed, 52 insertions(+), 12 deletions(-) |
| 17 | + |
| 18 | +diff --git a/pydevd_plugins/__init__.py b/pydevd_plugins/__init__.py |
| 19 | +index e4abcfa..f77af49 100644 |
| 20 | +--- a/pydevd_plugins/__init__.py |
| 21 | ++++ b/pydevd_plugins/__init__.py |
| 22 | +@@ -1,6 +1,3 @@ |
| 23 | +-try: |
| 24 | +- __import__("pkg_resources").declare_namespace(__name__) |
| 25 | +-except ImportError: # pragma: no cover |
| 26 | +- import pkgutil |
| 27 | ++import pkgutil |
| 28 | + |
| 29 | +- __path__ = pkgutil.extend_path(__path__, __name__) |
| 30 | ++__path__ = pkgutil.extend_path(__path__, __name__) |
| 31 | +diff --git a/pydevd_plugins/extensions/__init__.py b/pydevd_plugins/extensions/__init__.py |
| 32 | +index e4abcfa..f77af49 100644 |
| 33 | +--- a/pydevd_plugins/extensions/__init__.py |
| 34 | ++++ b/pydevd_plugins/extensions/__init__.py |
| 35 | +@@ -1,6 +1,3 @@ |
| 36 | +-try: |
| 37 | +- __import__("pkg_resources").declare_namespace(__name__) |
| 38 | +-except ImportError: # pragma: no cover |
| 39 | +- import pkgutil |
| 40 | ++import pkgutil |
| 41 | + |
| 42 | +- __path__ = pkgutil.extend_path(__path__, __name__) |
| 43 | ++__path__ = pkgutil.extend_path(__path__, __name__) |
| 44 | +diff --git a/tests/test_nodes.py b/tests/test_nodes.py |
| 45 | +index af73670..8ef8e94 100644 |
| 46 | +--- a/tests/test_nodes.py |
| 47 | ++++ b/tests/test_nodes.py |
| 48 | +@@ -843,8 +843,11 @@ def test_eq(node: ValueNode, value: Any, expected: Any) -> None: |
| 49 | + assert (value != node) != expected |
| 50 | + |
| 51 | + # Check hash except for unhashable types (dict/list). |
| 52 | +- if not isinstance(value, (dict, list)): |
| 53 | +- assert (node.__hash__() == value.__hash__()) == expected |
| 54 | ++ # Per Python's hash contract: if a == b, then hash(a) == hash(b) |
| 55 | ++ # Note: if a != b, hashes may or may not be equal (collisions are allowed) |
| 56 | ++ # E.g. Path('a') != 'a' but their hashes are equal as of Python 3.12 |
| 57 | ++ if not isinstance(value, (dict, list)) and expected: |
| 58 | ++ assert node.__hash__() == value.__hash__() |
| 59 | + |
| 60 | + |
| 61 | + @mark.parametrize( |
| 62 | +@@ -998,3 +1001,46 @@ def test_interpolation_result_readonly(flags: Any) -> None: |
| 63 | + # If no value was provided for the "readonly" flag, it should be set. |
| 64 | + if readonly is None: |
| 65 | + assert node._get_node_flag("readonly") |
| 66 | ++ |
| 67 | ++ |
| 68 | ++@mark.skipif( |
| 69 | ++ sys.version_info < (3, 12), |
| 70 | ++ reason="Hash collision between Path and str only exists in Python 3.12+", |
| 71 | ++) |
| 72 | ++def test_path_str_hash_collision_handling() -> None: |
| 73 | ++ """ |
| 74 | ++ Regression test for Python 3.12+ hash collision between Path and str. |
| 75 | ++ |
| 76 | ++ In Python 3.12+, Path('x') and 'x' have identical hashes but are not equal. |
| 77 | ++ This test verifies that OmegaConf's containers handle this collision correctly. |
| 78 | ++ """ |
| 79 | ++ from pathlib import Path |
| 80 | ++ |
| 81 | ++ path_str = "hello.txt" |
| 82 | ++ path_obj = Path(path_str) |
| 83 | ++ assert hash(path_obj) == hash(path_str) |
| 84 | ++ assert path_obj != path_str # type: ignore[comparison-overlap] |
| 85 | ++ |
| 86 | ++ # Test PathNode behavior with hash collision |
| 87 | ++ path_node = PathNode(path_obj) |
| 88 | ++ assert hash(path_node) == hash(path_str) |
| 89 | ++ assert path_node != path_str |
| 90 | ++ |
| 91 | ++ list_cfg1 = OmegaConf.create([path_obj]) |
| 92 | ++ assert path_obj in list_cfg1 |
| 93 | ++ assert path_str not in list_cfg1 |
| 94 | ++ |
| 95 | ++ list_cfg2 = OmegaConf.create([path_str]) |
| 96 | ++ assert path_obj not in list_cfg2 |
| 97 | ++ assert path_str in list_cfg2 |
| 98 | ++ |
| 99 | ++ # Test DictConfig with both types as values |
| 100 | ++ dict_cfg = OmegaConf.create( |
| 101 | ++ { |
| 102 | ++ "by_path": {"file": path_obj}, |
| 103 | ++ "by_string": {"file": path_str}, |
| 104 | ++ } |
| 105 | ++ ) |
| 106 | ++ assert dict_cfg.by_path.file == path_obj |
| 107 | ++ assert dict_cfg.by_string.file == path_str |
| 108 | ++ assert dict_cfg.by_path.file != dict_cfg.by_string.file |
| 109 | +-- |
| 110 | +2.43.0 |
| 111 | + |
0 commit comments