Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ repos:
- id: check-yaml
- id: check-ast
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.12.9
rev: v0.14.3
hooks:
- id: ruff
args: [ --fix, --exit-non-zero-on-fix ]
- id: ruff-format
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.17.1
rev: v1.18.2
hooks:
- id: mypy
args:
Expand Down
4 changes: 2 additions & 2 deletions pyiceberg/avro/codecs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

from __future__ import annotations

from typing import Dict, Literal, Optional, Type
from typing import Dict, Literal, Type

from typing_extensions import TypeAlias

Expand All @@ -40,7 +40,7 @@

AVRO_CODEC_KEY = "avro.codec"

KNOWN_CODECS: Dict[AvroCompressionCodec, Optional[Type[Codec]]] = {
KNOWN_CODECS: Dict[AvroCompressionCodec, Type[Codec] | None] = {
"null": None,
"bzip2": BZip2Codec,
"snappy": SnappyCodec,
Expand Down
3 changes: 1 addition & 2 deletions pyiceberg/avro/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
Dict,
List,
Tuple,
Union,
cast,
)

Expand Down Expand Up @@ -137,7 +136,7 @@ class StreamingBinaryDecoder(BinaryDecoder):
__slots__ = "_input_stream"
_input_stream: InputStream

def __init__(self, input_stream: Union[bytes, InputStream]) -> None:
def __init__(self, input_stream: bytes | InputStream) -> None:
"""Reader is a Python object on which we can call read, seek, and tell."""
if isinstance(input_stream, bytes):
# In the case of bytes, we wrap it into a BytesIO to make it a stream
Expand Down
21 changes: 8 additions & 13 deletions pyiceberg/avro/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
Dict,
Generic,
List,
Optional,
Type,
TypeVar,
)
Expand Down Expand Up @@ -85,7 +84,7 @@ def meta(self) -> Dict[str, str]:
def sync(self) -> bytes:
return self._data[2]

def compression_codec(self) -> Optional[Type[Codec]]:
def compression_codec(self) -> Type[Codec] | None:
"""Get the file's compression codec algorithm from the file's metadata.

In the case of a null codec, we return a None indicating that we
Expand Down Expand Up @@ -146,20 +145,20 @@ class AvroFile(Generic[D]):
"block",
)
input_file: InputFile
read_schema: Optional[Schema]
read_schema: Schema | None
read_types: Dict[int, Callable[..., StructProtocol]]
read_enums: Dict[int, Callable[..., Enum]]
header: AvroFileHeader
schema: Schema
reader: Reader

decoder: BinaryDecoder
block: Optional[Block[D]]
block: Block[D] | None

def __init__(
self,
input_file: InputFile,
read_schema: Optional[Schema] = None,
read_schema: Schema | None = None,
read_types: Dict[int, Callable[..., StructProtocol]] = EMPTY_DICT,
read_enums: Dict[int, Callable[..., Enum]] = EMPTY_DICT,
) -> None:
Expand All @@ -186,9 +185,7 @@ def __enter__(self) -> AvroFile[D]:

return self

def __exit__(
self, exctype: Optional[Type[BaseException]], excinst: Optional[BaseException], exctb: Optional[TracebackType]
) -> None:
def __exit__(self, exctype: Type[BaseException] | None, excinst: BaseException | None, exctb: TracebackType | None) -> None:
"""Perform cleanup when exiting the scope of a 'with' statement."""

def __iter__(self) -> AvroFile[D]:
Expand Down Expand Up @@ -242,7 +239,7 @@ def __init__(
output_file: OutputFile,
file_schema: Schema,
schema_name: str,
record_schema: Optional[Schema] = None,
record_schema: Schema | None = None,
metadata: Dict[str, str] = EMPTY_DICT,
) -> None:
self.output_file = output_file
Expand Down Expand Up @@ -270,9 +267,7 @@ def __enter__(self) -> AvroOutputFile[D]:

return self

def __exit__(
self, exctype: Optional[Type[BaseException]], excinst: Optional[BaseException], exctb: Optional[TracebackType]
) -> None:
def __exit__(self, exctype: Type[BaseException] | None, excinst: BaseException | None, exctb: TracebackType | None) -> None:
"""Perform cleanup when exiting the scope of a 'with' statement."""
self.output_stream.close()

Expand All @@ -289,7 +284,7 @@ def _write_header(self) -> None:
header = AvroFileHeader(MAGIC, meta, self.sync_bytes)
construct_writer(META_SCHEMA).write(self.encoder, header)

def compression_codec(self) -> Optional[Type[Codec]]:
def compression_codec(self) -> Type[Codec] | None:
"""Get the file's compression codec algorithm from the file's metadata.

In the case of a null codec, we return a None indicating that we
Expand Down
11 changes: 5 additions & 6 deletions pyiceberg/avro/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
Callable,
List,
Mapping,
Optional,
Tuple,
)
from uuid import UUID
Expand Down Expand Up @@ -292,7 +291,7 @@ def __repr__(self) -> str:
class OptionReader(Reader):
option: Reader = dataclassfield()

def read(self, decoder: BinaryDecoder) -> Optional[Any]:
def read(self, decoder: BinaryDecoder) -> Any | None:
# For the Iceberg spec it is required to set the default value to null
# From https://iceberg.apache.org/spec/#avro
# Optional fields must always set the Avro field default value to null.
Expand Down Expand Up @@ -320,14 +319,14 @@ class StructReader(Reader):
"_hash",
"_max_pos",
)
field_readers: Tuple[Tuple[Optional[int], Reader], ...]
field_readers: Tuple[Tuple[int | None, Reader], ...]
create_struct: Callable[..., StructProtocol]
struct: StructType
field_reader_functions = Tuple[Tuple[Optional[str], int, Optional[Callable[[BinaryDecoder], Any]]], ...]
field_reader_functions = Tuple[Tuple[str | None, int, Callable[[BinaryDecoder], Any] | None], ...]

def __init__(
self,
field_readers: Tuple[Tuple[Optional[int], Reader], ...],
field_readers: Tuple[Tuple[int | None, Reader], ...],
create_struct: Callable[..., StructProtocol],
struct: StructType,
) -> None:
Expand All @@ -339,7 +338,7 @@ def __init__(
if not isinstance(self.create_struct(), StructProtocol):
raise ValueError(f"Incompatible with StructProtocol: {self.create_struct}")

reading_callbacks: List[Tuple[Optional[int], Callable[[BinaryDecoder], Any]]] = []
reading_callbacks: List[Tuple[int | None, Callable[[BinaryDecoder], Any]]] = []
max_pos = -1
for pos, field in field_readers:
if pos is not None:
Expand Down
Loading