Skip to content

Commit

Permalink
black & isort all files
Browse files Browse the repository at this point in the history
  • Loading branch information
MKuranowski committed Apr 28, 2024
1 parent 1e872e7 commit a51fe12
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 18 deletions.
7 changes: 3 additions & 4 deletions aiocsv/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@

__url__ = "https://github.com/MKuranowski/aiocsv"
__author__ = "Mikołaj Kuranowski"
__email__ = "".join(chr(i) for i in [109, 107, 117, 114, 97, 110, 111, 119, 115, 107, 105,
64, 103, 109, 97, 105, 108, 46, 99, 111, 109])
__email__ = "[email protected]"

__copyright__ = "© Copyright 2020-2024 Mikołaj Kuranowski"
__license__ = "MIT"

from .readers import AsyncReader, AsyncDictReader
from .writers import AsyncWriter, AsyncDictWriter
from .readers import AsyncDictReader, AsyncReader
from .writers import AsyncDictWriter, AsyncWriter

__all__ = ["AsyncReader", "AsyncDictReader", "AsyncWriter", "AsyncDictWriter"]
6 changes: 2 additions & 4 deletions aiocsv/_parser.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# © Copyright 2020-2024 Mikołaj Kuranowski
# SPDX-License-Identifier: MIT

from typing import Awaitable, AsyncIterator, List

from .protocols import WithAsyncRead, DialectLike
from typing import AsyncIterator, Awaitable, List

from .protocols import DialectLike, WithAsyncRead

class _Parser:
"""Return type of the "Parser" function, not accessible from Python."""
Expand All @@ -14,5 +13,4 @@ class _Parser:
@property
def line_num(self) -> int: ...


def Parser(reader: WithAsyncRead, dialect: DialectLike) -> _Parser: ...
4 changes: 2 additions & 2 deletions aiocsv/parser.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# © Copyright 2020-2024 Mikołaj Kuranowski
# SPDX-License-Identifier: MIT

import csv
from enum import IntEnum, auto
from typing import Any, AsyncIterator, Awaitable, Generator, List, Optional, Sequence, Union
import csv

from .protocols import DialectLike, WithAsyncRead

Expand Down Expand Up @@ -250,7 +250,7 @@ def add_char(self, c: str) -> None:
def save_field(self) -> None:
field: Union[str, float, None]
if self.dialect.skipinitialspace:
field = "".join(self.field_so_far[self.find_first_non_space(self.field_so_far):])
field = "".join(self.field_so_far[self.find_first_non_space(self.field_so_far) :])
else:
field = "".join(self.field_so_far)

Expand Down
16 changes: 12 additions & 4 deletions aiocsv/readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
# SPDX-License-Identifier: MIT

import csv
from warnings import warn
from typing import Dict, List, Optional, Sequence
from warnings import warn

from .protocols import WithAsyncRead

try:
Expand All @@ -18,6 +19,7 @@ class AsyncReader:
Additional keyword arguments are passed to the underlying csv.reader instance.
Iterating over this object returns parsed CSV rows (List[str]).
"""

def __init__(self, asyncfile: WithAsyncRead, **csvreaderparams) -> None:
self._file = asyncfile

Expand Down Expand Up @@ -50,9 +52,15 @@ class AsyncDictReader:
like you would to csv.DictReader.
Iterating over this object returns parsed CSV rows (Dict[str, str]).
"""
def __init__(self, asyncfile: WithAsyncRead, fieldnames: Optional[Sequence[str]] = None,
restkey: Optional[str] = None, restval: Optional[str] = None,
**csvreaderparams) -> None:

def __init__(
self,
asyncfile: WithAsyncRead,
fieldnames: Optional[Sequence[str]] = None,
restkey: Optional[str] = None,
restval: Optional[str] = None,
**csvreaderparams,
) -> None:

self.fieldnames: Optional[List[str]] = list(fieldnames) if fieldnames else None
self.restkey: Optional[str] = restkey
Expand Down
10 changes: 6 additions & 4 deletions aiocsv/writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class AsyncWriter:
Additional keyword arguments are passed to the underlying csv.writer instance.
"""

def __init__(self, asyncfile: WithAsyncWrite, **csvwriterparams) -> None:
self._file = asyncfile
self._buffer = io.StringIO(newline="")
Expand All @@ -24,8 +25,7 @@ def dialect(self) -> csv.Dialect:
return self._csv_writer.dialect

async def _rewrite_buffer(self) -> None:
"""Writes the current value of self._buffer to the actual target file.
"""
"""Writes the current value of self._buffer to the actual target file."""
# Write buffer value to the file
await self._file.write(self._buffer.getvalue())

Expand Down Expand Up @@ -61,8 +61,10 @@ class AsyncDictWriter:
Additional keyword arguments are passed to the underlying csv.DictWriter instance.
"""
def __init__(self, asyncfile: WithAsyncWrite, fieldnames: Sequence[str],
**csvdictwriterparams) -> None:

def __init__(
self, asyncfile: WithAsyncWrite, fieldnames: Sequence[str], **csvdictwriterparams
) -> None:
self._file = asyncfile
self._buffer = io.StringIO(newline="")
self._csv_writer = csv.DictWriter(self._buffer, fieldnames, **csvdictwriterparams)
Expand Down

0 comments on commit a51fe12

Please sign in to comment.