Skip to content

Commit 98a9377

Browse files
committed
Fix inconsistent capitalization in Roundtrip.
1 parent 795ecdb commit 98a9377

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from typing import Any, Generic, TypeVar
2+
3+
# Define generic type variables
4+
T = TypeVar("T")
5+
SerializedForm = TypeVar("SerializedForm")
6+
7+
8+
class Roundtrip(Generic[T, SerializedForm]):
9+
def serialize(self, value: T) -> SerializedForm:
10+
"""Serialize a value of type T to its SerializedForm."""
11+
raise NotImplementedError
12+
13+
def parse(self, serialized: SerializedForm) -> T:
14+
"""Parse the SerializedForm back to type T."""
15+
raise NotImplementedError
16+
17+
@classmethod
18+
def identity(cls) -> "Roundtrip[T, T]":
19+
"""Return an identity Roundtrip that does no transformation."""
20+
21+
class Identity(Roundtrip[Any, Any]):
22+
def serialize(self, value: Any) -> Any:
23+
return value
24+
25+
def parse(self, serialized: Any) -> Any:
26+
return serialized
27+
28+
return Identity()

python/selfie-lib/selfie_lib/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from .Literals import LiteralValue as LiteralValue
1111
from .ParseException import ParseException as ParseException
1212
from .PerCharacterEscaper import PerCharacterEscaper as PerCharacterEscaper
13-
from .RoundTrip import Roundtrip as Roundtrip
13+
from .Roundtrip import Roundtrip as Roundtrip
1414
from .Selfie import expect_selfie as expect_selfie
1515
from .Slice import Slice as Slice
1616
from .Snapshot import Snapshot as Snapshot

0 commit comments

Comments
 (0)