Skip to content

Commit

Permalink
Merge pull request #23 from n-takumasa/fixup
Browse files Browse the repository at this point in the history
IO[str] -> SupportsXxx[str]
  • Loading branch information
n-takumasa authored Apr 16, 2024
2 parents 945cbe5 + 3a88cd9 commit e940cf8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
7 changes: 4 additions & 3 deletions jsonc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@

if TYPE_CHECKING:
from collections.abc import Callable
from typing import Any, TextIO
from typing import Any

from jsonc._add_comments import Comments
from jsonc._types import SupportsRead, SupportsWrite

__version__ = "0.0.0"
__all__ = [
Expand All @@ -40,7 +41,7 @@


def load(
fp: TextIO,
fp: SupportsRead[str],
*,
cls: type[json.JSONDecoder] | None = None,
object_hook: Callable[[dict[Any, Any]], Any] | None = None,
Expand Down Expand Up @@ -144,7 +145,7 @@ def dumps(

def dump(
obj: Any,
fp: TextIO,
fp: SupportsWrite[str],
*,
skipkeys=False,
ensure_ascii=True,
Expand Down
15 changes: 15 additions & 0 deletions jsonc/_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from typing import Protocol, TypeVar

_T_co = TypeVar("_T_co", covariant=True)
_T_contra = TypeVar("_T_contra", contravariant=True)


# fmt: off
# Vendored from
# https://github.com/python/typeshed/blob/7c8e82fe483a40ec4cb0a2505cfdb0f3e7cc81d9/stdlib/_typeshed/__init__.pyi#L239-L253
class SupportsRead(Protocol[_T_co]):
def read(self, length: int = ..., /) -> _T_co: ...

class SupportsWrite(Protocol[_T_contra]):
def write(self, s: _T_contra, /) -> object: ...
# fmt: on

0 comments on commit e940cf8

Please sign in to comment.