Skip to content

Commit

Permalink
Modify type annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
thombashi committed Jun 16, 2021
1 parent e35449b commit af9d015
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 26 deletions.
19 changes: 9 additions & 10 deletions pytablewriter/writer/_table_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
import copy
import math
import warnings
from typing import Any # noqa
from typing import Dict, List, Mapping, Optional, Sequence, Union, cast
from typing import Any, Dict, List, Mapping, Optional, Sequence, Union, cast

import typepy
from dataproperty import (
Expand Down Expand Up @@ -275,16 +274,16 @@ def __init__(self, **kwargs) -> None:
self.write_callback = kwargs.get(
"write_callback", lambda _iter_count, _iter_length: None # defaults to NOP callback
)
self._iter_count = None # type: Optional[int]
self._iter_count: Optional[int] = None

self.__default_style = kwargs.get("default_style", Style())

self.__col_style_list = [] # type: List[Optional[Style]]
self.__col_style_list: List[Optional[Style]] = []
self.column_styles = kwargs.get("column_styles", [])

self._style_filters = [] # type: List[StyleFilterFunc]
self._style_filters: List[StyleFilterFunc] = []
self._styler = self._create_styler(self)
self.style_filter_kwargs = kwargs.get("style_filter_kwargs", {}) # type: Dict[str, Any]
self.style_filter_kwargs: Dict[str, Any] = kwargs.get("style_filter_kwargs", {})
self.__colorize_terminal = kwargs.get("colorize_terminal", True)
self.__enable_ansi_escape = kwargs.get("enable_ansi_escape", True)

Expand Down Expand Up @@ -317,10 +316,10 @@ def __clear_preprocess_status(self) -> None:
self._is_complete_value_matrix_preprocess = False

def __clear_preprocess_data(self) -> None:
self._column_dp_list = [] # type: List[ColumnDataProperty]
self._table_headers = [] # type: List[str]
self._table_value_matrix = [] # type: List[Union[List[str], Dict]]
self._table_value_dp_matrix = [] # type: Sequence[Sequence[DataProperty]]
self._column_dp_list: List[ColumnDataProperty] = []
self._table_headers: List[str] = []
self._table_value_matrix: List[Union[List[str], Dict]] = []
self._table_value_dp_matrix: Sequence[Sequence[DataProperty]] = []

@property
def headers(self) -> Sequence[str]:
Expand Down
14 changes: 7 additions & 7 deletions pytablewriter/writer/binary/_excel.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import abc
import copy
import warnings
from typing import Any, Dict, Optional, cast # noqa
from typing import Any, Dict, Optional, cast

import dataproperty
import typepy
Expand Down Expand Up @@ -32,7 +32,7 @@ def workbook(self) -> Optional[ExcelWorkbookInterface]:
def __init__(self, **kwargs) -> None:
super().__init__(**kwargs)

self._workbook = None # type: Optional[ExcelWorkbookInterface]
self._workbook: Optional[ExcelWorkbookInterface] = None

self._dp_extractor.type_value_map = {
typepy.Typecode.INFINITY: "Inf",
Expand All @@ -43,8 +43,8 @@ def __init__(self, **kwargs) -> None:
self._last_header_row = self.first_header_row
self._first_data_row = self.last_header_row + 1
self._first_data_col = 0
self._last_data_row = None # type: Optional[int]
self._last_data_col = None # type: Optional[int]
self._last_data_row: Optional[int] = None
self._last_data_col: Optional[int] = None

self._current_data_row = self._first_data_row

Expand Down Expand Up @@ -261,7 +261,7 @@ class ExcelXlsTableWriter(ExcelTableWriter):
def __init__(self, **kwargs) -> None:
super().__init__(**kwargs)

self.__col_style_table = {} # type: Dict[int, Any]
self.__col_style_table: Dict[int, Any] = {}

def _open(self, workbook_path: str) -> None:
self._workbook = ExcelWorkbookXls(workbook_path)
Expand Down Expand Up @@ -399,8 +399,8 @@ def __init__(self, **kwargs) -> None:
self.TableFormat.NAN: self.Default.NAN_FORMAT,
}

self.__col_cell_format_cache = {} # type: Dict[int, Any]
self.__col_numprops_table = {} # type: Dict[int, Dict]
self.__col_cell_format_cache: Dict[int, Any] = {}
self.__col_numprops_table: Dict[int, Dict] = {}

def _open(self, workbook_path: str) -> None:
self._workbook = ExcelWorkbookXlsx(workbook_path)
Expand Down
6 changes: 3 additions & 3 deletions pytablewriter/writer/binary/_excel_workbook.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import abc
import warnings
from typing import Dict, Optional # noqa
from typing import Any, Dict, Optional

import typepy

Expand Down Expand Up @@ -43,8 +43,8 @@ def file_path(self) -> Optional[str]:

def _clear(self) -> None:
self._workbook = None
self._file_path = None # type: Optional[str]
self._worksheet_table = {} # type: Dict
self._file_path: Optional[str] = None
self._worksheet_table: Dict[str, Any] = {}

def __init__(self, file_path: str) -> None:
self._clear()
Expand Down
4 changes: 2 additions & 2 deletions pytablewriter/writer/binary/_pandas.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Optional # noqa
from typing import Optional

import tabledata

Expand Down Expand Up @@ -38,7 +38,7 @@ def __init__(self, **kwargs) -> None:

self._quoting_flags = copy.deepcopy(dataproperty.NOT_QUOTING_FLAGS)

self.__filepath = None # type: Optional[str]
self.__filepath: Optional[str] = None

def is_opened(self) -> bool:
return self.__filepath is not None
Expand Down
4 changes: 2 additions & 2 deletions pytablewriter/writer/text/_html.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import copy
import warnings
from typing import Any, List, Optional, Tuple, cast # noqa
from typing import Any, Optional, Tuple, cast

import dataproperty
import typepy
Expand Down Expand Up @@ -54,7 +54,7 @@ def __init__(self, **kwargs) -> None:
self._dp_extractor.preprocessor.line_break_repl = "<br>"
self._dp_extractor.preprocessor.is_escape_html_tag = False
self._quoting_flags = copy.deepcopy(dataproperty.NOT_QUOTING_FLAGS)
self._table_tag = None # type: Any
self._table_tag: Any = None

self.enable_ansi_escape = False

Expand Down
2 changes: 1 addition & 1 deletion pytablewriter/writer/text/_text_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def __init__(self, **kwargs) -> None:

self._init_cross_point_maps()

self._col_separator_style_filters = [] # type: List[ColSeparatorStyleFilterFunc]
self._col_separator_style_filters: List[ColSeparatorStyleFilterFunc] = []

if "theme" in kwargs:
self.set_theme(kwargs["theme"])
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
REQUIREMENT_DIR = "requirements"
ENCODING = "utf8"

pkg_info = {} # type: Dict[str, str]
pkg_info: Dict[str, str] = {}


def get_release_command_class() -> Dict[str, setuptools.Command]:
Expand Down

0 comments on commit af9d015

Please sign in to comment.