From 9ecbdb09162da4d563799aa93d422db85b2c324b Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Sun, 20 Mar 2022 10:16:29 -0700 Subject: [PATCH] use generator instead of iterable in function return annotation --- docs/parsers/mpstat_s.md | 10 ++++++---- docs/parsers/pidstat_s.md | 10 ++++++---- docs/parsers/rsync_s.md | 10 ++++++---- docs/parsers/universal.md | 19 +++++++++---------- jc/parsers/foo_s.py | 4 ++-- jc/parsers/mpstat_s.py | 4 ++-- jc/parsers/pidstat_s.py | 4 ++-- jc/parsers/rsync_s.py | 4 ++-- 8 files changed, 35 insertions(+), 30 deletions(-) diff --git a/docs/parsers/mpstat_s.md b/docs/parsers/mpstat_s.md index 66f3ef8b..51aceb14 100644 --- a/docs/parsers/mpstat_s.md +++ b/docs/parsers/mpstat_s.md @@ -101,10 +101,12 @@ Examples: ```python @add_jc_meta -def parse(data: Iterable[str], - raw: bool = False, - quiet: bool = False, - ignore_exceptions: bool = False) -> Union[Iterable[Dict], tuple] +def parse( + data: Iterable[str], + raw: bool = False, + quiet: bool = False, + ignore_exceptions: bool = False +) -> Union[Generator[Dict, None, None], tuple] ``` Main text parsing generator function. Returns an iterator object. diff --git a/docs/parsers/pidstat_s.md b/docs/parsers/pidstat_s.md index d94feebb..e8fc7872 100644 --- a/docs/parsers/pidstat_s.md +++ b/docs/parsers/pidstat_s.md @@ -83,10 +83,12 @@ Examples: ```python @add_jc_meta -def parse(data: Iterable[str], - raw: bool = False, - quiet: bool = False, - ignore_exceptions: bool = False) -> Union[Iterable[Dict], tuple] +def parse( + data: Iterable[str], + raw: bool = False, + quiet: bool = False, + ignore_exceptions: bool = False +) -> Union[Generator[Dict, None, None], tuple] ``` Main text parsing generator function. Returns an iterator object. diff --git a/docs/parsers/rsync_s.md b/docs/parsers/rsync_s.md index a77a2a2e..d78ad24c 100644 --- a/docs/parsers/rsync_s.md +++ b/docs/parsers/rsync_s.md @@ -90,10 +90,12 @@ Examples: ```python @add_jc_meta -def parse(data: Iterable[str], - raw: bool = False, - quiet: bool = False, - ignore_exceptions: bool = False) -> Union[Iterable[Dict], tuple] +def parse( + data: Iterable[str], + raw: bool = False, + quiet: bool = False, + ignore_exceptions: bool = False +) -> Union[Generator[Dict, None, None], tuple] ``` Main text parsing generator function. Returns an iterator object. diff --git a/docs/parsers/universal.md b/docs/parsers/universal.md index 2a01569f..40889af5 100644 --- a/docs/parsers/universal.md +++ b/docs/parsers/universal.md @@ -54,7 +54,8 @@ Returns: ### sparse\_table\_parse ```python -def sparse_table_parse(data: List[str], delim: str = '\u2063') -> List[Dict] +def sparse_table_parse(data: Iterable[str], + delim: str = '\u2063') -> List[Dict] ``` Parse tables with missing column data or with spaces in column data. @@ -77,16 +78,14 @@ Example Table: Parameters: - data: (list) Text data to parse that has been split into lines - via .splitlines(). Item 0 must be the header row. - Any spaces in header names should be changed to - underscore '_'. You should also ensure headers are - lowercase by using .lower(). Do not change the - position of header names as the positions are used - to find the data. + data: (iter) An iterable of string lines (e.g. str.splitlines()) + Item 0 must be the header row. Any spaces in header + names should be changed to underscore '_'. You + should also ensure headers are lowercase by using + .lower(). Do not change the position of header + names as the positions are used to find the data. - Also, ensure there are no blank lines (list items) - in the data. + Also, ensure there are no blank line items. delim: (string) Delimiter to use. By default `u\\2063` (invisible separator) is used since it is unlikely diff --git a/jc/parsers/foo_s.py b/jc/parsers/foo_s.py index 229ac345..496cd005 100644 --- a/jc/parsers/foo_s.py +++ b/jc/parsers/foo_s.py @@ -40,7 +40,7 @@ Examples: {example output} ... """ -from typing import Dict, Iterable, Union +from typing import Dict, Iterable, Generator, Union import jc.utils from jc.streaming import ( add_jc_meta, streaming_input_type_check, streaming_line_input_type_check, raise_or_yield @@ -90,7 +90,7 @@ def parse( raw: bool = False, quiet: bool = False, ignore_exceptions: bool = False -) -> Union[Iterable[Dict], tuple]: +) -> Union[Generator[Dict, None, None], tuple]: """ Main text parsing generator function. Returns an iterator object. diff --git a/jc/parsers/mpstat_s.py b/jc/parsers/mpstat_s.py index 8eea4730..e06f91b6 100644 --- a/jc/parsers/mpstat_s.py +++ b/jc/parsers/mpstat_s.py @@ -90,7 +90,7 @@ Examples: {"cpu":"all","intr_s":"37.61","type":"interrupts","time":"03:15:06 PM"} ... """ -from typing import Dict, Iterable, Union +from typing import Dict, Iterable, Generator, Union import jc.utils from jc.parsers.universal import simple_table_parse from jc.streaming import ( @@ -145,7 +145,7 @@ def parse( raw: bool = False, quiet: bool = False, ignore_exceptions: bool = False -) -> Union[Iterable[Dict], tuple]: +) -> Union[Generator[Dict, None, None], tuple]: """ Main text parsing generator function. Returns an iterator object. diff --git a/jc/parsers/pidstat_s.py b/jc/parsers/pidstat_s.py index 3a7b7b62..d9b688bd 100644 --- a/jc/parsers/pidstat_s.py +++ b/jc/parsers/pidstat_s.py @@ -72,7 +72,7 @@ Examples: {"time":"1646859134","uid":"0","pid":"9","percent_usr":"0.00","perc...} ... """ -from typing import Dict, Iterable, Union +from typing import Dict, Iterable, Generator, Union import jc.utils from jc.streaming import ( add_jc_meta, streaming_input_type_check, streaming_line_input_type_check, raise_or_yield @@ -126,7 +126,7 @@ def parse( raw: bool = False, quiet: bool = False, ignore_exceptions: bool = False -) -> Union[Iterable[Dict], tuple]: +) -> Union[Generator[Dict, None, None], tuple]: """ Main text parsing generator function. Returns an iterator object. diff --git a/jc/parsers/rsync_s.py b/jc/parsers/rsync_s.py index 4ecfe9d2..f6ecddd6 100644 --- a/jc/parsers/rsync_s.py +++ b/jc/parsers/rsync_s.py @@ -80,7 +80,7 @@ Examples: ... """ import re -from typing import Dict, Iterable, Union +from typing import Dict, Iterable, Generator, Union import jc.utils from jc.streaming import ( add_jc_meta, streaming_input_type_check, streaming_line_input_type_check, raise_or_yield @@ -139,7 +139,7 @@ def parse( raw: bool = False, quiet: bool = False, ignore_exceptions: bool = False -) -> Union[Iterable[Dict], tuple]: +) -> Union[Generator[Dict, None, None], tuple]: """ Main text parsing generator function. Returns an iterator object.