Skip to content
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 docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
import sys
from pathlib import Path

from pontos.version import __version__ # Moved to top for Ruff E402 compliance

source_directory = str(Path(__file__).parent.absolute())

sys.path.insert(0, source_directory)

from pontos.version import __version__

# -- Project information -----------------------------------------------------

Expand Down
5 changes: 5 additions & 0 deletions pontos/version/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ def __le__(self, other: Any) -> bool:
def __str__(self) -> str:
"""A string representation of the version"""

# --- Added for Ruff PLW1641 compliance ---
@abstractmethod
def __hash__(self) -> int:
raise NotImplementedError # pragma: no cover

def __repr__(self) -> str:
"""A representation of the Version"""
return f"<{self.__class__.__name__}('{self}')>"
Expand Down
4 changes: 4 additions & 0 deletions pontos/version/schemes/_pep440.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ def __le__(self, other: Any) -> bool:
def __str__(self) -> str:
return str(self._version)

# --- Added for Ruff PLW1641 compliance ---
def __hash__(self) -> int:
return hash(self._version)


class PEP440VersionCalculator(VersionCalculator):
version_cls = PEP440Version
Expand Down
4 changes: 4 additions & 0 deletions pontos/version/schemes/_semantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ def __str__(self) -> str:
"""A string representation of the version"""
return str(self._version_info)

# --- Added for Ruff PLW1641 compliance ---
def __hash__(self) -> int:
return hash(self._version_info)

@classmethod
def from_string(cls, version: str) -> "SemanticVersion":
"""
Expand Down
8 changes: 8 additions & 0 deletions tests/version/schemes/test_pep440.py
Original file line number Diff line number Diff line change
Expand Up @@ -1003,3 +1003,11 @@ def test_next_dev_version(self):
f"{release_version} is not the next expected dev version "
f"{assert_version} for {current_version}",
)

def test_hash(self):
self.assertEqual(hash(Version("22.2.2")), hash(Version("22.2.2")))
self.assertNotEqual(hash(Version("22.2.1")), hash(Version("22.2.2")))
self.assertNotEqual(hash(SemanticVersion("22.2.2")), hash("22.2.2"))
self.assertNotEqual(
hash(SemanticVersion("22.2.1")), hash(SemanticVersion("22.2.2"))
)
19 changes: 18 additions & 1 deletion tests/version/schemes/test_semantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@

from pontos.version._errors import VersionError
from pontos.version.schemes._pep440 import PEP440Version
from pontos.version.schemes._semantic import SemanticVersion as Version
from pontos.version.schemes._semantic import (
SemanticVersion,
)
from pontos.version.schemes._semantic import (
SemanticVersion as Version,
)
from pontos.version.schemes._semantic import (
SemanticVersionCalculator as VersionCalculator,
)
Expand Down Expand Up @@ -1026,3 +1031,15 @@ def test_next_dev_version(self):
f"{release_version} is not the expected next development "
f"version {assert_version} for {current_version}",
)

def test_hash(self):
self.assertEqual(
hash(SemanticVersion("22.2.2")), hash(SemanticVersion("22.2.2"))
)
self.assertNotEqual(
hash(SemanticVersion("22.2.1")), hash(SemanticVersion("22.2.2"))
)
self.assertNotEqual(hash(SemanticVersion("22.2.2")), hash("22.2.2"))
self.assertNotEqual(
hash(SemanticVersion("22.2.1")), hash(SemanticVersion("22.2.2"))
)
21 changes: 21 additions & 0 deletions tests/version/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,24 @@ def test_equal_raises(self):

with self.assertRaises(ValueError):
self.assertNotEqual(PEP440Version("22.2.2"), 22)

def test_hash(self):
self.assertEqual(
hash(PEP440Version("22.2.2")), hash(PEP440Version("22.2.2"))
)
self.assertNotEqual(
hash(PEP440Version("22.2.1")), hash(PEP440Version("22.2.2"))
)
self.assertNotEqual(hash(SemanticVersion("22.2.2")), hash("22.2.2"))
self.assertNotEqual(
hash(SemanticVersion("22.2.1")), hash(SemanticVersion("22.2.2"))
)

def test_hash_semantic(self):
self.assertEqual(
hash(SemanticVersion("22.2.2")), hash(SemanticVersion("22.2.2"))
)
self.assertNotEqual(
hash(SemanticVersion("22.2.1")), hash(SemanticVersion("22.2.2"))
)
self.assertNotEqual(hash(SemanticVersion("22.2.2")), hash("22.2.2"))
Loading