-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from zkurtz/zdev
use runtime module protocol checks
- Loading branch information
Showing
3 changed files
with
28 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,10 @@ | ||
"""Constants for dummio.""" | ||
|
||
import typing | ||
from pathlib import Path | ||
from typing import Any, Protocol, TypeAlias | ||
from typing import Any, TypeAlias | ||
|
||
PathType: TypeAlias = str | Path | ||
AnyDict: TypeAlias = dict[Any, Any] | ||
|
||
# pyright expect a type var to be used at least twice within a single method. It's having | ||
# trouble respecting how it's use *accross* methods of a class. | ||
T = typing.TypeVar("T") # pyright: ignore | ||
|
||
DEFAULT_ENCODING = "utf-8" | ||
DEFAULT_WRITE_MODE = "w" | ||
|
||
|
||
@typing.runtime_checkable | ||
class ModuleProtocol(Protocol): | ||
"""Protocol for dummio's IO modules.""" | ||
|
||
def save(self, data: T, *, filepath: PathType) -> None: # pyright: ignore[reportInvalidTypeVarUse] | ||
"""Declares the signature of an IO module save method.""" | ||
... | ||
|
||
def load(self, filepath: PathType) -> T: # pyright: ignore[reportInvalidTypeVarUse] | ||
"""Declares the signature of an IO module load method.""" | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters