Skip to content

Commit

Permalink
Python: Fix D401 pydocstyle issues (apache#8401)
Browse files Browse the repository at this point in the history
* Fix D401 pydocstyle issues

* Update python/tests/conftest.py

---------

Co-authored-by: Fokko Driesprong <[email protected]>
  • Loading branch information
TjuAachen and Fokko authored Aug 28, 2023
1 parent 25c8e19 commit 51d07f5
Show file tree
Hide file tree
Showing 45 changed files with 359 additions and 359 deletions.
2 changes: 1 addition & 1 deletion python/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ repos:
- id: pydocstyle
args:
[
"--ignore=D100,D102,D101,D103,D104,D106,D107,D203,D212,D213,D401,D404,D405,D406,D407,D411,D413,D415,D417",
"--ignore=D100,D102,D101,D103,D104,D106,D107,D203,D212,D213,D404,D405,D406,D407,D411,D413,D415,D417",
]
additional_dependencies:
- tomli==2.0.1
14 changes: 7 additions & 7 deletions python/pyiceberg/avro/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ def skip(self, n: int) -> None:
"""Skip n bytes."""

def read_boolean(self) -> bool:
"""Reads a value from the stream as a boolean.
"""Read a value from the stream as a boolean.
A boolean is written as a single byte
whose value is either 0 (false) or 1 (true).
"""
return ord(self.read(1)) == 1

def read_int(self) -> int:
"""Reads an int/long value.
"""Read an int/long value.
int/long values are written using variable-length, zigzag coding.
"""
Expand All @@ -70,18 +70,18 @@ def read_int(self) -> int:
return datum

def read_ints(self, n: int) -> Tuple[int, ...]:
"""Reads a list of integers."""
"""Read a list of integers."""
return tuple(self.read_int() for _ in range(n))

def read_int_bytes_dict(self, n: int, dest: Dict[int, bytes]) -> None:
"""Reads a dictionary of integers for keys and bytes for values into a destination dictionary."""
"""Read a dictionary of integers for keys and bytes for values into a destination dictionary."""
for _ in range(n):
k = self.read_int()
v = self.read_bytes()
dest[k] = v

def read_float(self) -> float:
"""Reads a value from the stream as a float.
"""Read a value from the stream as a float.
A float is written as 4 bytes.
The float is converted into a 32-bit integer using a method equivalent to
Expand All @@ -90,7 +90,7 @@ def read_float(self) -> float:
return float(cast(Tuple[float, ...], STRUCT_FLOAT.unpack(self.read(4)))[0])

def read_double(self) -> float:
"""Reads a value from the stream as a double.
"""Read a value from the stream as a double.
A double is written as 8 bytes.
The double is converted into a 64-bit integer using a method equivalent to
Expand All @@ -104,7 +104,7 @@ def read_bytes(self) -> bytes:
return self.read(num_bytes) if num_bytes > 0 else b""

def read_utf8(self) -> str:
"""Reads an utf-8 encoded string from the stream.
"""Read an utf-8 encoded string from the stream.
A string is encoded as a long followed by
that many bytes of UTF-8 encoded character data.
Expand Down
8 changes: 4 additions & 4 deletions python/pyiceberg/avro/encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def write(self, b: bytes) -> None:
self._output_stream.write(b)

def write_boolean(self, boolean: bool) -> None:
"""A boolean is written as a single byte whose value is either 0 (false) or 1 (true).
"""Write a boolean as a single byte whose value is either 0 (false) or 1 (true).
Args:
boolean: The boolean to write.
Expand All @@ -48,11 +48,11 @@ def write_int(self, integer: int) -> None:
self.write(bytearray([datum]))

def write_float(self, f: float) -> None:
"""A float is written as 4 bytes."""
"""Write a float as 4 bytes."""
self.write(STRUCT_FLOAT.pack(f))

def write_double(self, f: float) -> None:
"""A double is written as 8 bytes."""
"""Write a double as 8 bytes."""
self.write(STRUCT_DOUBLE.pack(f))

def write_bytes(self, b: bytes) -> None:
Expand All @@ -61,7 +61,7 @@ def write_bytes(self, b: bytes) -> None:
self.write(b)

def write_utf8(self, s: str) -> None:
"""A string is encoded as a long followed by that many bytes of UTF-8 encoded character data."""
"""Encode a string as a long followed by that many bytes of UTF-8 encoded character data."""
self.write_bytes(s.encode("utf-8"))

def write_uuid(self, uuid: UUID) -> None:
Expand Down
18 changes: 9 additions & 9 deletions python/pyiceberg/avro/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@ class Block(Generic[D]):
position: int = 0

def __iter__(self) -> Block[D]:
"""Returns an iterator for the Block class."""
"""Return an iterator for the Block class."""
return self

def has_next(self) -> bool:
return self.position < self.block_records

def __next__(self) -> D:
"""Returns the next item when iterating over the Block class."""
"""Return the next item when iterating over the Block class."""
if self.has_next():
self.position += 1
return self.reader.read(self.block_decoder)
Expand Down Expand Up @@ -160,9 +160,9 @@ def __init__(
self.block = None

def __enter__(self) -> AvroFile[D]:
"""Generates a reader tree for the payload within an avro file.
"""Generate a reader tree for the payload within an avro file.
Returns:
Return:
A generator returning the AvroStructs.
"""
with self.input_file.open() as f:
Expand All @@ -179,10 +179,10 @@ def __enter__(self) -> AvroFile[D]:
def __exit__(
self, exctype: Optional[Type[BaseException]], excinst: Optional[BaseException], exctb: Optional[TracebackType]
) -> None:
"""Performs cleanup when exiting the scope of a 'with' statement."""
"""Perform cleanup when exiting the scope of a 'with' statement."""

def __iter__(self) -> AvroFile[D]:
"""Returns an iterator for the AvroFile class."""
"""Return an iterator for the AvroFile class."""
return self

def _read_block(self) -> int:
Expand All @@ -202,7 +202,7 @@ def _read_block(self) -> int:
return block_records

def __next__(self) -> D:
"""Returns the next item when iterating over the AvroFile class."""
"""Return the next item when iterating over the AvroFile class."""
if self.block and self.block.has_next():
return next(self.block)

Expand Down Expand Up @@ -238,7 +238,7 @@ def __init__(self, output_file: OutputFile, schema: Schema, schema_name: str, me

def __enter__(self) -> AvroOutputFile[D]:
"""
Opens the file and writes the header.
Open the file and writes the header.
Returns:
The file object to write records to
Expand All @@ -254,7 +254,7 @@ def __enter__(self) -> AvroOutputFile[D]:
def __exit__(
self, exctype: Optional[Type[BaseException]], excinst: Optional[BaseException], exctb: Optional[TracebackType]
) -> None:
"""Performs cleanup when exiting the scope of a 'with' statement."""
"""Perform cleanup when exiting the scope of a 'with' statement."""
self.output_stream.close()

def _write_header(self) -> None:
Expand Down
18 changes: 9 additions & 9 deletions python/pyiceberg/avro/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def skip(self, decoder: ReadableDecoder) -> None:
...

def __repr__(self) -> str:
"""Returns the string representation of the Reader class."""
"""Return the string representation of the Reader class."""
return f"{self.__class__.__name__}()"


Expand Down Expand Up @@ -217,11 +217,11 @@ def skip(self, decoder: ReadableDecoder) -> None:
decoder.skip(len(self))

def __len__(self) -> int:
"""Returns the length of an instance of the FixedReader class."""
"""Return the length of an instance of the FixedReader class."""
return self._len

def __repr__(self) -> str:
"""Returns the string representation of the FixedReader class."""
"""Return the string representation of the FixedReader class."""
return f"FixedReader({self._len})"


Expand Down Expand Up @@ -263,7 +263,7 @@ def skip(self, decoder: ReadableDecoder) -> None:
decoder.skip_bytes()

def __repr__(self) -> str:
"""Returns the string representation of the DecimalReader class."""
"""Return the string representation of the DecimalReader class."""
return f"DecimalReader({self.precision}, {self.scale})"


Expand Down Expand Up @@ -346,19 +346,19 @@ def skip(self, decoder: ReadableDecoder) -> None:
field.skip(decoder)

def __eq__(self, other: Any) -> bool:
"""Returns the equality of two instances of the StructReader class."""
"""Return the equality of two instances of the StructReader class."""
return (
self.field_readers == other.field_readers and self.create_struct == other.create_struct
if isinstance(other, StructReader)
else False
)

def __repr__(self) -> str:
"""Returns the string representation of the StructReader class."""
"""Return the string representation of the StructReader class."""
return f"StructReader(({','.join(repr(field) for field in self.field_readers)}), {repr(self.create_struct)})"

def __hash__(self) -> int:
"""Returns a hashed representation of the StructReader class."""
"""Return a hashed representation of the StructReader class."""
return self._hash


Expand Down Expand Up @@ -392,7 +392,7 @@ def skip(self, decoder: ReadableDecoder) -> None:
_skip_map_array(decoder, lambda: self.element.skip(decoder))

def __hash__(self) -> int:
"""Returns a hashed representation of the ListReader class."""
"""Return a hashed representation of the ListReader class."""
return self._hash


Expand Down Expand Up @@ -492,5 +492,5 @@ def skip() -> None:
_skip_map_array(decoder, skip)

def __hash__(self) -> int:
"""Returns a hashed representation of the MapReader class."""
"""Return a hashed representation of the MapReader class."""
return self._hash
8 changes: 4 additions & 4 deletions python/pyiceberg/avro/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
def construct_reader(
file_schema: Union[Schema, IcebergType], read_types: Dict[int, Callable[..., StructProtocol]] = EMPTY_DICT
) -> Reader:
"""Constructs a reader from a file schema.
"""Construct a reader from a file schema.
Args:
file_schema (Schema | IcebergType): The schema of the Avro file.
Expand All @@ -120,7 +120,7 @@ def construct_reader(


def construct_writer(file_schema: Union[Schema, IcebergType]) -> Writer:
"""Constructs a writer from a file schema.
"""Construct a writer from a file schema.
Args:
file_schema (Schema | IcebergType): The schema of the Avro file.
Expand All @@ -132,7 +132,7 @@ def construct_writer(file_schema: Union[Schema, IcebergType]) -> Writer:


class ConstructWriter(SchemaVisitorPerPrimitiveType[Writer]):
"""Constructs a writer tree from an Iceberg schema."""
"""Construct a writer tree from an Iceberg schema."""

def schema(self, schema: Schema, struct_result: Writer) -> Writer:
return struct_result
Expand Down Expand Up @@ -198,7 +198,7 @@ def resolve(
read_types: Dict[int, Callable[..., StructProtocol]] = EMPTY_DICT,
read_enums: Dict[int, Callable[..., Enum]] = EMPTY_DICT,
) -> Reader:
"""Resolves the file and read schema to produce a reader.
"""Resolve the file and read schema to produce a reader.
Args:
file_schema (Schema | IcebergType): The schema of the Avro file.
Expand Down
14 changes: 7 additions & 7 deletions python/pyiceberg/avro/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def write(self, encoder: BinaryEncoder, val: Any) -> Any:
...

def __repr__(self) -> str:
"""Returns string representation of this object."""
"""Return string representation of this object."""
return f"{self.__class__.__name__}()"


Expand Down Expand Up @@ -116,11 +116,11 @@ def write(self, encoder: BinaryEncoder, val: bytes) -> None:
encoder.write(val)

def __len__(self) -> int:
"""Returns the length of this object."""
"""Return the length of this object."""
return self._len

def __repr__(self) -> str:
"""Returns string representation of this object."""
"""Return string representation of this object."""
return f"FixedWriter({self._len})"


Expand All @@ -140,7 +140,7 @@ def write(self, encoder: BinaryEncoder, val: Any) -> None:
return encoder.write(decimal_to_bytes(val, byte_length=decimal_required_bytes(self.precision)))

def __repr__(self) -> str:
"""Returns string representation of this object."""
"""Return string representation of this object."""
return f"DecimalWriter({self.precision}, {self.scale})"


Expand All @@ -165,15 +165,15 @@ def write(self, encoder: BinaryEncoder, val: StructType) -> None:
writer.write(encoder, value)

def __eq__(self, other: Any) -> bool:
"""Implements the equality operator for this object."""
"""Implement the equality operator for this object."""
return self.field_writers == other.field_writers if isinstance(other, StructWriter) else False

def __repr__(self) -> str:
"""Returns string representation of this object."""
"""Return string representation of this object."""
return f"StructWriter({','.join(repr(field) for field in self.field_writers)})"

def __hash__(self) -> int:
"""Returns the hash of the writer as hash of this object."""
"""Return the hash of the writer as hash of this object."""
return hash(self.field_writers)


Expand Down
Loading

0 comments on commit 51d07f5

Please sign in to comment.