Skip to content

Commit

Permalink
Use Iterables instead of Sequences for input "many" types
Browse files Browse the repository at this point in the history
  • Loading branch information
faph committed Sep 16, 2023
1 parent 72260ba commit 419681c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 20 deletions.
17 changes: 3 additions & 14 deletions src/py_adapter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,8 @@
import inspect
import logging
import uuid
from collections.abc import Iterator
from typing import (
Any,
Callable,
Dict,
List,
Optional,
Sequence,
Type,
TypeVar,
Union,
cast,
)
from collections.abc import Iterable, Iterator
from typing import Any, Callable, Dict, List, Optional, Type, TypeVar, Union, cast

import avro.schema
import dateutil.parser
Expand Down Expand Up @@ -114,7 +103,7 @@ def serialize(obj: Any, *, format: str, writer_schema: bytes = b"") -> bytes:
return data


def serialize_many(objs: Sequence[Any], *, format: str, writer_schema: bytes = b"") -> bytes:
def serialize_many(objs: Iterable[Any], *, format: str, writer_schema: bytes = b"") -> bytes:
"""
Serialize multiple objects using a serialization format supported by **py-adapter**
Expand Down
6 changes: 3 additions & 3 deletions src/py_adapter/plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import functools
import logging
import sys
from collections.abc import Iterator
from typing import TYPE_CHECKING, Sequence
from collections.abc import Iterable, Iterator
from typing import TYPE_CHECKING

import pluggy

Expand Down Expand Up @@ -113,7 +113,7 @@ def serialize(obj: "py_adapter.Basic", writer_schema: bytes) -> bytes:


@_hookspec(firstresult=True)
def serialize_many(objs: Sequence["py_adapter.Basic"], writer_schema: bytes) -> bytes:
def serialize_many(objs: Iterable["py_adapter.Basic"], writer_schema: bytes) -> bytes:
"""
Hook specification. Serialize multiple Python objects of basic types to the format supported by the implementing
plugin.
Expand Down
5 changes: 2 additions & 3 deletions src/py_adapter/plugin/_avro.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
"""

import io
from collections.abc import Iterator
from typing import Sequence
from collections.abc import Iterable, Iterator

import orjson

Expand Down Expand Up @@ -45,7 +44,7 @@ def serialize(obj: py_adapter.Basic, writer_schema: bytes) -> bytes:


@py_adapter.plugin.hook
def serialize_many(objs: Sequence[py_adapter.Basic], writer_schema: bytes) -> bytes:
def serialize_many(objs: Iterable[py_adapter.Basic], writer_schema: bytes) -> bytes:
"""
Serialize multiple Python objects of basic types as Avro container file format.
Expand Down

0 comments on commit 419681c

Please sign in to comment.