Skip to content

Commit fd032ec

Browse files
committed
Use old-style generics.
1 parent de859c7 commit fd032ec

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

python/selfie-lib/selfie_lib/Atomic.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
from typing import Callable
1+
from typing import Callable, Generic, TypeVar
22

3+
T = TypeVar("T")
34

4-
class AtomicReference[T]:
5+
6+
class AtomicReference(Generic[T]):
57
"""
68
This has the same API as Java's AtomicReference, but it doesn't make any sense in the Python runtime.
79
The point of keeping it is that it makes the port from Kotlin more 1:1

python/selfie-lib/selfie_lib/FS.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
from abc import ABC, abstractmethod
22
from pathlib import Path
3-
from typing import Callable, Iterator
3+
from typing import Callable, Iterator, TypeVar
44

55
from selfie_lib.TypedPath import TypedPath
66

7+
T = TypeVar("T")
8+
79

810
class FS(ABC):
911
def file_exists(self, typed_path: TypedPath) -> bool:
1012
return Path(typed_path.absolute_path).is_file()
1113

12-
def file_walk[T](
14+
def file_walk(
1315
self, typed_path: TypedPath, walk: Callable[[Iterator[TypedPath]], T]
1416
) -> T:
1517
def walk_generator(path: TypedPath) -> Iterator[TypedPath]:

python/selfie-lib/selfie_lib/Selfie.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def expect_selfie(actual: str) -> StringSelfie: ...
1717

1818

1919
@overload
20-
def expect_selfie[T](actual: T) -> ReprSelfie[T]: ...
20+
def expect_selfie(actual: T) -> ReprSelfie[T]: ...
2121

2222

2323
def expect_selfie(

python/selfie-lib/selfie_lib/SelfieImplementations.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import base64
22
from abc import ABC, abstractmethod
33
from itertools import chain
4-
from typing import Any, List, Optional
4+
from typing import Any, Generic, List, Optional, TypeVar
55

66
from .Literals import (
77
LiteralFormat,
@@ -15,8 +15,10 @@
1515
from .SnapshotSystem import DiskStorage, Mode, SnapshotSystem, _selfieSystem
1616
from .WriteTracker import recordCall as recordCall
1717

18+
T = TypeVar("T")
1819

19-
class ReprSelfie[T]:
20+
21+
class ReprSelfie(Generic[T]):
2022
def __init__(self, actual: T):
2123
self.actual = actual
2224

@@ -168,12 +170,12 @@ def to_be(self, expected: str) -> str:
168170
)
169171

170172

171-
def _checkSrc[T](value: T) -> T:
173+
def _checkSrc(value: T) -> T:
172174
_selfieSystem().mode.can_write(False, recordCall(True), _selfieSystem())
173175
return value
174176

175177

176-
def _toBeDidntMatch[T](expected: Optional[T], actual: T, fmt: LiteralFormat[T]) -> T:
178+
def _toBeDidntMatch(expected: Optional[T], actual: T, fmt: LiteralFormat[T]) -> T:
177179
call = recordCall(False)
178180
writable = _selfieSystem().mode.can_write(expected is None, call, _selfieSystem())
179181
if writable:

0 commit comments

Comments
 (0)