Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace black by Ruff Formatter #127

Merged
merged 6 commits into from
Jan 5, 2024
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
11 changes: 4 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,12 @@ repos:
- id: check-ast
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version (Used for linting)
rev: v0.1.0
rev: v0.1.8
hooks:
- id: ruff
args: [ --fix, --exit-non-zero-on-fix ]
- repo: https://github.com/ambv/black
rev: 23.10.0
hooks:
- id: black
args: [--skip-string-normalization]
args: [ --fix, --exit-non-zero-on-fix, --preview ]
- id: ruff-format
args: [ --preview ]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.6.1
hooks:
Expand Down
1 change: 1 addition & 0 deletions pyiceberg/avro/codecs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
so don't confuse it with the Python's "codecs", which is a package mainly for
converting character sets (https://docs.python.org/3/library/codecs.html).
"""

from __future__ import annotations

from typing import Dict, Optional, Type
Expand Down
6 changes: 2 additions & 4 deletions pyiceberg/avro/codecs/codec.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ class Codec(ABC):

@staticmethod
@abstractmethod
def compress(data: bytes) -> tuple[bytes, int]:
...
def compress(data: bytes) -> tuple[bytes, int]: ...

@staticmethod
@abstractmethod
def decompress(data: bytes) -> bytes:
...
def decompress(data: bytes) -> bytes: ...
1 change: 1 addition & 0 deletions pyiceberg/avro/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# under the License.
# pylint: disable=W0621
"""Avro reader for reading Avro files."""

from __future__ import annotations

import io
Expand Down
7 changes: 3 additions & 4 deletions pyiceberg/avro/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
The reader tree can be changed in such a way that the
read schema is different, while respecting the read schema.
"""

from __future__ import annotations

from abc import abstractmethod
Expand Down Expand Up @@ -85,12 +86,10 @@ def _skip_map_array(decoder: BinaryDecoder, skip_entry: Callable[[], None]) -> N

class Reader(Singleton):
@abstractmethod
def read(self, decoder: BinaryDecoder) -> Any:
...
def read(self, decoder: BinaryDecoder) -> Any: ...

@abstractmethod
def skip(self, decoder: BinaryDecoder) -> None:
...
def skip(self, decoder: BinaryDecoder) -> None: ...

def __repr__(self) -> str:
"""Return the string representation of the Reader class."""
Expand Down
4 changes: 1 addition & 3 deletions pyiceberg/avro/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,7 @@ def resolve_reader(
Raises:
NotImplementedError: If attempting to resolve an unrecognized object type.
"""
return visit_with_partner(
file_schema, read_schema, ReadSchemaResolver(read_types, read_enums), SchemaPartnerAccessor()
) # type: ignore
return visit_with_partner(file_schema, read_schema, ReadSchemaResolver(read_types, read_enums), SchemaPartnerAccessor()) # type: ignore


class EnumReader(Reader):
Expand Down
4 changes: 2 additions & 2 deletions pyiceberg/avro/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
Constructing a writer tree from the schema makes it easy
to decouple the writing implementation from the schema.
"""

from __future__ import annotations

from abc import abstractmethod
Expand All @@ -43,8 +44,7 @@
@dataclass(frozen=True)
class Writer(Singleton):
@abstractmethod
def write(self, encoder: BinaryEncoder, val: Any) -> Any:
...
def write(self, encoder: BinaryEncoder, val: Any) -> Any: ...

def __repr__(self) -> str:
"""Return string representation of this object."""
Expand Down
45 changes: 16 additions & 29 deletions pyiceberg/cli/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,48 +40,37 @@ class Output(ABC):
"""Output interface for exporting."""

@abstractmethod
def exception(self, ex: Exception) -> None:
...
def exception(self, ex: Exception) -> None: ...

@abstractmethod
def identifiers(self, identifiers: List[Identifier]) -> None:
...
def identifiers(self, identifiers: List[Identifier]) -> None: ...

@abstractmethod
def describe_table(self, table: Table) -> None:
...
def describe_table(self, table: Table) -> None: ...

@abstractmethod
def files(self, table: Table, history: bool) -> None:
...
def files(self, table: Table, history: bool) -> None: ...

@abstractmethod
def describe_properties(self, properties: Properties) -> None:
...
def describe_properties(self, properties: Properties) -> None: ...

@abstractmethod
def text(self, response: str) -> None:
...
def text(self, response: str) -> None: ...

@abstractmethod
def schema(self, schema: Schema) -> None:
...
def schema(self, schema: Schema) -> None: ...

@abstractmethod
def spec(self, spec: PartitionSpec) -> None:
...
def spec(self, spec: PartitionSpec) -> None: ...

@abstractmethod
def uuid(self, uuid: Optional[UUID]) -> None:
...
def uuid(self, uuid: Optional[UUID]) -> None: ...

@abstractmethod
def version(self, version: str) -> None:
...
def version(self, version: str) -> None: ...

@abstractmethod
def describe_refs(self, refs: List[Tuple[str, SnapshotRefType, Dict[str, str]]]) -> None:
...
def describe_refs(self, refs: List[Tuple[str, SnapshotRefType, Dict[str, str]]]) -> None: ...


class ConsoleOutput(Output):
Expand Down Expand Up @@ -252,10 +241,8 @@ def version(self, version: str) -> None:
self._out({"version": version})

def describe_refs(self, refs: List[Tuple[str, SnapshotRefType, Dict[str, str]]]) -> None:
self._out(
[
{"name": name, "type": type, detail_key: detail_val}
for name, type, detail in refs
for detail_key, detail_val in detail.items()
]
)
self._out([
{"name": name, "type": type, detail_key: detail_val}
for name, type, detail in refs
for detail_key, detail_val in detail.items()
])
1 change: 1 addition & 0 deletions pyiceberg/conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
implementation, a concrete function is registered for each generic conversion function. For PrimitiveType
implementations that share the same conversion logic, registrations can be stacked.
"""

import uuid
from datetime import date, datetime, time
from decimal import Decimal
Expand Down
33 changes: 11 additions & 22 deletions pyiceberg/expressions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,11 @@ class Unbound(Generic[B], ABC):
"""Represents an unbound value expression."""

@abstractmethod
def bind(self, schema: Schema, case_sensitive: bool = True) -> B:
...
def bind(self, schema: Schema, case_sensitive: bool = True) -> B: ...

@property
@abstractmethod
def as_bound(self) -> Type[Bound]:
...
def as_bound(self) -> Type[Bound]: ...


class BoundTerm(Term[L], Bound, ABC):
Expand Down Expand Up @@ -142,8 +140,7 @@ class UnboundTerm(Term[Any], Unbound[BoundTerm[L]], ABC):
"""Represents an unbound term."""

@abstractmethod
def bind(self, schema: Schema, case_sensitive: bool = True) -> BoundTerm[L]:
...
def bind(self, schema: Schema, case_sensitive: bool = True) -> BoundTerm[L]: ...


class Reference(UnboundTerm[Any]):
Expand Down Expand Up @@ -352,8 +349,7 @@ def __eq__(self, other: Any) -> bool:

@property
@abstractmethod
def as_unbound(self) -> Type[UnboundPredicate[Any]]:
...
def as_unbound(self) -> Type[UnboundPredicate[Any]]: ...


class UnboundPredicate(Generic[L], Unbound[BooleanExpression], BooleanExpression, ABC):
Expand All @@ -367,13 +363,11 @@ def __eq__(self, other: Any) -> bool:
return self.term == other.term if isinstance(other, self.__class__) else False

@abstractmethod
def bind(self, schema: Schema, case_sensitive: bool = True) -> BooleanExpression:
...
def bind(self, schema: Schema, case_sensitive: bool = True) -> BooleanExpression: ...

@property
@abstractmethod
def as_bound(self) -> Type[BoundPredicate[L]]:
...
def as_bound(self) -> Type[BoundPredicate[L]]: ...


class UnaryPredicate(UnboundPredicate[Any], ABC):
Expand All @@ -387,8 +381,7 @@ def __repr__(self) -> str:

@property
@abstractmethod
def as_bound(self) -> Type[BoundUnaryPredicate[Any]]:
...
def as_bound(self) -> Type[BoundUnaryPredicate[Any]]: ...


class BoundUnaryPredicate(BoundPredicate[L], ABC):
Expand All @@ -398,8 +391,7 @@ def __repr__(self) -> str:

@property
@abstractmethod
def as_unbound(self) -> Type[UnaryPredicate]:
...
def as_unbound(self) -> Type[UnaryPredicate]: ...

def __getnewargs__(self) -> Tuple[BoundTerm[L]]:
"""Pickle the BoundUnaryPredicate class."""
Expand Down Expand Up @@ -575,8 +567,7 @@ def __getnewargs__(self) -> Tuple[BoundTerm[L], Set[Literal[L]]]:

@property
@abstractmethod
def as_unbound(self) -> Type[SetPredicate[L]]:
...
def as_unbound(self) -> Type[SetPredicate[L]]: ...


class BoundIn(BoundSetPredicate[L]):
Expand Down Expand Up @@ -705,8 +696,7 @@ def __repr__(self) -> str:

@property
@abstractmethod
def as_bound(self) -> Type[BoundLiteralPredicate[L]]:
...
def as_bound(self) -> Type[BoundLiteralPredicate[L]]: ...


class BoundLiteralPredicate(BoundPredicate[L], ABC):
Expand All @@ -729,8 +719,7 @@ def __repr__(self) -> str:

@property
@abstractmethod
def as_unbound(self) -> Type[LiteralPredicate[L]]:
...
def as_unbound(self) -> Type[LiteralPredicate[L]]: ...


class BoundEqualTo(BoundLiteralPredicate[L]):
Expand Down
3 changes: 1 addition & 2 deletions pyiceberg/expressions/literals.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ def value(self) -> L:

@singledispatchmethod
@abstractmethod
def to(self, type_var: IcebergType) -> Literal[L]:
... # pragma: no cover
def to(self, type_var: IcebergType) -> Literal[L]: ... # pragma: no cover

def __repr__(self) -> str:
"""Return the string representation of the Literal class."""
Expand Down
19 changes: 7 additions & 12 deletions pyiceberg/io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
for returning an InputFile instance, an OutputFile instance, and deleting a file given
its location.
"""

from __future__ import annotations

import importlib
Expand Down Expand Up @@ -78,20 +79,16 @@ class InputStream(Protocol):
"""

@abstractmethod
def read(self, size: int = 0) -> bytes:
...
def read(self, size: int = 0) -> bytes: ...

@abstractmethod
def seek(self, offset: int, whence: int = SEEK_SET) -> int:
...
def seek(self, offset: int, whence: int = SEEK_SET) -> int: ...

@abstractmethod
def tell(self) -> int:
...
def tell(self) -> int: ...

@abstractmethod
def close(self) -> None:
...
def close(self) -> None: ...

def __enter__(self) -> InputStream:
"""Provide setup when opening an InputStream using a 'with' statement."""
Expand All @@ -112,12 +109,10 @@ class OutputStream(Protocol): # pragma: no cover
"""

@abstractmethod
def write(self, b: bytes) -> int:
...
def write(self, b: bytes) -> int: ...

@abstractmethod
def close(self) -> None:
...
def close(self) -> None: ...

@abstractmethod
def __enter__(self) -> OutputStream:
Expand Down
1 change: 1 addition & 0 deletions pyiceberg/io/fsspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
"""FileIO implementation for reading and writing table files that uses fsspec compatible filesystems."""

import errno
import json
import logging
Expand Down
1 change: 1 addition & 0 deletions pyiceberg/io/pyarrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
type to use. Theoretically, this allows the supported storage types to grow naturally
with the pyarrow library.
"""

from __future__ import annotations

import concurrent.futures
Expand Down
Loading