alitheg commented on code in PR #825:
URL: 
https://github.com/apache/tooling-trusted-releases/pull/825#discussion_r2894733056


##########
atr/models/safe.py:
##########
@@ -38,25 +63,50 @@ def __repr__(self) -> str:
     def __str__(self) -> str:
         return self._value
 
+    @classmethod
+    def __get_pydantic_core_schema__(cls, _source_type: Any, _handler: Any) -> 
Any:
+        import pydantic_core.core_schema as core_schema
 
-class VersionName:
-    """A version name that has been validated against the cache or database."""
+        return core_schema.no_info_plain_validator_function(
+            lambda v: cls(v) if isinstance(v, str) else v,
+            serialization=core_schema.to_string_ser_schema(),
+        )
 
-    __slots__ = ("_value",)
 
-    def __init__(self, value: str) -> None:
-        self._value = value
+class ProjectName(Alphanumeric):
+    """A project name that has been validated for safety."""
 
-    def __eq__(self, other: object) -> bool:
-        if isinstance(other, VersionName):
-            return self._value == other._value
-        return NotImplemented
 
-    def __hash__(self) -> int:
-        return hash(self._value)
+class ReleaseName(Alphanumeric):
+    """A release name composed from a validated ProjectName and VersionName."""
 
-    def __repr__(self) -> str:
-        return f"VersionName({self._value!r})"
+    @classmethod
+    def _valid_chars(cls) -> frozenset[str]:
+        return _VERSION_CHARS
 
-    def __str__(self) -> str:
-        return self._value
+
+class VersionName(Alphanumeric):
+    """A version name that has been validated for safety"""
+
+    @classmethod
+    def _valid_chars(cls) -> frozenset[str]:
+        return _VERSION_CHARS
+
+    def _additional_validations(self, value):
+        if value[0] not in _ALPHANUM:
+            raise ValueError("A version should start with an alphanumeric 
character")
+        if value[-1] not in _ALPHANUM:
+            raise ValueError("A version should end with an alphanumeric 
character")
+
+
+def _assert_standard_safe_syntax(value: str) -> None:

Review Comment:
   Yeah - for the types we're implementing, alphanumeric is sufficient to 
disallow JSON etc. But if we wanted to bring in safe types for other things we 
may want to have another class here which explicitly validates those in or out. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to