mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-17 00:07:37 +02:00
update type hints with mypy help
This commit is contained in:
18
jc/lib.py
18
jc/lib.py
@ -6,7 +6,7 @@ import sys
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import importlib
|
import importlib
|
||||||
from typing import Dict, Iterable, List, Any, Union, Iterator, Optional
|
from typing import Dict, List, Iterable, Union, Iterator, Optional
|
||||||
from jc import appdirs
|
from jc import appdirs
|
||||||
|
|
||||||
__version__ = '1.18.2'
|
__version__ = '1.18.2'
|
||||||
@ -143,10 +143,10 @@ def _get_parser(parser_mod_name):
|
|||||||
def parse(
|
def parse(
|
||||||
parser_mod_name: str,
|
parser_mod_name: str,
|
||||||
data: Union[str, Iterable[str]],
|
data: Union[str, Iterable[str]],
|
||||||
quiet: Optional[bool] = False,
|
quiet: bool = False,
|
||||||
raw: Optional[bool] = False,
|
raw: bool = False,
|
||||||
ignore_exceptions: Optional[bool] = None,
|
ignore_exceptions: bool = None,
|
||||||
**kwargs: Optional[Any]
|
**kwargs
|
||||||
) -> Union[Dict, List[Dict], Iterator[Dict]]:
|
) -> Union[Dict, List[Dict], Iterator[Dict]]:
|
||||||
"""
|
"""
|
||||||
Parse the string data using the supplied parser module.
|
Parse the string data using the supplied parser module.
|
||||||
@ -224,7 +224,7 @@ def plugin_parser_mod_list() -> List[str]:
|
|||||||
"""
|
"""
|
||||||
return [_cliname_to_modname(p) for p in local_parsers]
|
return [_cliname_to_modname(p) for p in local_parsers]
|
||||||
|
|
||||||
def parser_info(parser_mod_name: str) -> Dict:
|
def parser_info(parser_mod_name: str) -> Union[Dict, None]:
|
||||||
"""
|
"""
|
||||||
Returns a dictionary that includes the module metadata.
|
Returns a dictionary that includes the module metadata.
|
||||||
|
|
||||||
@ -237,7 +237,7 @@ def parser_info(parser_mod_name: str) -> Dict:
|
|||||||
parser_mod = _get_parser(parser_mod_name)
|
parser_mod = _get_parser(parser_mod_name)
|
||||||
|
|
||||||
if hasattr(parser_mod, 'info'):
|
if hasattr(parser_mod, 'info'):
|
||||||
info_dict = {}
|
info_dict: Dict = {}
|
||||||
info_dict['name'] = parser_mod_name
|
info_dict['name'] = parser_mod_name
|
||||||
info_dict['argument'] = _parser_argument(parser_mod_name)
|
info_dict['argument'] = _parser_argument(parser_mod_name)
|
||||||
parser_entry = vars(parser_mod.info)
|
parser_entry = vars(parser_mod.info)
|
||||||
@ -251,7 +251,9 @@ def parser_info(parser_mod_name: str) -> Dict:
|
|||||||
|
|
||||||
return info_dict
|
return info_dict
|
||||||
|
|
||||||
def all_parser_info() -> List[Dict]:
|
return None
|
||||||
|
|
||||||
|
def all_parser_info() -> List[Optional[Dict]]:
|
||||||
"""
|
"""
|
||||||
Returns a list of dictionaris that includes metadata for all modules.
|
Returns a list of dictionaris that includes metadata for all modules.
|
||||||
"""
|
"""
|
||||||
|
@ -39,7 +39,7 @@ Examples:
|
|||||||
[]
|
[]
|
||||||
"""
|
"""
|
||||||
import jc.utils
|
import jc.utils
|
||||||
from typing import Optional, List, Dict
|
from typing import List, Dict
|
||||||
|
|
||||||
|
|
||||||
class info():
|
class info():
|
||||||
@ -81,8 +81,8 @@ def _process(proc_data: List[Dict]) -> List[Dict]:
|
|||||||
|
|
||||||
def parse(
|
def parse(
|
||||||
data: str,
|
data: str,
|
||||||
raw: Optional[bool] = False,
|
raw: bool = False,
|
||||||
quiet: Optional[bool] = False
|
quiet: bool = False
|
||||||
) -> List[Dict]:
|
) -> List[Dict]:
|
||||||
"""
|
"""
|
||||||
Main text parsing function
|
Main text parsing function
|
||||||
@ -100,7 +100,7 @@ def parse(
|
|||||||
jc.utils.compatibility(__name__, info.compatible, quiet)
|
jc.utils.compatibility(__name__, info.compatible, quiet)
|
||||||
jc.utils.input_type_check(data)
|
jc.utils.input_type_check(data)
|
||||||
|
|
||||||
raw_output = []
|
raw_output: List = []
|
||||||
|
|
||||||
if jc.utils.has_data(data):
|
if jc.utils.has_data(data):
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ Examples:
|
|||||||
{example output}
|
{example output}
|
||||||
...
|
...
|
||||||
"""
|
"""
|
||||||
from typing import Optional, Dict, Iterable
|
from typing import Dict, Iterable
|
||||||
import jc.utils
|
import jc.utils
|
||||||
from jc.utils import stream_success, stream_error
|
from jc.utils import stream_success, stream_error
|
||||||
from jc.exceptions import ParseError
|
from jc.exceptions import ParseError
|
||||||
@ -93,9 +93,9 @@ def _process(proc_data: Dict) -> Dict:
|
|||||||
|
|
||||||
def parse(
|
def parse(
|
||||||
data: Iterable[str],
|
data: Iterable[str],
|
||||||
raw: Optional[bool] = False,
|
raw: bool = False,
|
||||||
quiet: Optional[bool] = False,
|
quiet: bool = False,
|
||||||
ignore_exceptions: Optional[bool] = False
|
ignore_exceptions: bool = False
|
||||||
) -> Iterable[Dict]:
|
) -> Iterable[Dict]:
|
||||||
"""
|
"""
|
||||||
Main text parsing generator function. Returns an iterator object.
|
Main text parsing generator function. Returns an iterator object.
|
||||||
@ -121,7 +121,7 @@ def parse(
|
|||||||
jc.utils.streaming_input_type_check(data)
|
jc.utils.streaming_input_type_check(data)
|
||||||
|
|
||||||
for line in data:
|
for line in data:
|
||||||
output_line = {}
|
output_line: Dict = {}
|
||||||
try:
|
try:
|
||||||
jc.utils.streaming_line_input_type_check(line)
|
jc.utils.streaming_line_input_type_check(line)
|
||||||
|
|
||||||
|
@ -127,7 +127,7 @@ def has_data(data: str) -> bool:
|
|||||||
return bool(data and not data.isspace())
|
return bool(data and not data.isspace())
|
||||||
|
|
||||||
|
|
||||||
def convert_to_int(value: Union[str, float]) -> int:
|
def convert_to_int(value: Union[str, float]) -> Union[int, None]:
|
||||||
"""
|
"""
|
||||||
Converts string and float input to int. Strips all non-numeric
|
Converts string and float input to int. Strips all non-numeric
|
||||||
characters from strings.
|
characters from strings.
|
||||||
@ -157,7 +157,7 @@ def convert_to_int(value: Union[str, float]) -> int:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def convert_to_float(value: Union[str, int]) -> float:
|
def convert_to_float(value: Union[str, int]) -> Union[float, None]:
|
||||||
"""
|
"""
|
||||||
Converts string and int input to float. Strips all non-numeric
|
Converts string and int input to float. Strips all non-numeric
|
||||||
characters from strings.
|
characters from strings.
|
||||||
|
Reference in New Issue
Block a user