diff --git a/CHANGELOG b/CHANGELOG index 03a3d4af..28541063 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,11 @@ +1.8.2 (TBD) +=========== + +- On Windows, ``py.path.local``s which differ only in case now have the same + Python hash value. Previously, such paths were considered equal but had + different hashes, which is not allowed and breaks the assumptions made by + dicts, sets and other users of hashes. + 1.8.1 (2019-12-27) ================== diff --git a/py/_path/local.py b/py/_path/local.py index de6dcb4f..1385a039 100644 --- a/py/_path/local.py +++ b/py/_path/local.py @@ -163,7 +163,10 @@ def __init__(self, path=None, expanduser=False): self.strpath = abspath(path) def __hash__(self): - return hash(self.strpath) + s = self.strpath + if iswin32: + s = s.lower() + return hash(s) def __eq__(self, other): s1 = fspath(self) diff --git a/testing/path/test_local.py b/testing/path/test_local.py index ae009362..a6b8f476 100644 --- a/testing/path/test_local.py +++ b/testing/path/test_local.py @@ -164,6 +164,17 @@ def test_tilde_expansion(self, monkeypatch, tmpdir): p = py.path.local("~", expanduser=True) assert p == os.path.expanduser("~") + @pytest.mark.skipif( + not sys.platform.startswith("win32"), reason="case insensitive only on windows" + ) + def test_eq_hash_are_case_insensitive_on_windows(self): + a = py.path.local("/some/path") + b = py.path.local("/some/PATH") + assert a == b + assert hash(a) == hash(b) + assert a in {b} + assert a in {b: 'b'} + def test_eq_with_strings(self, path1): path1 = path1.join('sampledir') path2 = str(path1)