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 re
|
||||
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
|
||||
|
||||
__version__ = '1.18.2'
|
||||
@ -143,10 +143,10 @@ def _get_parser(parser_mod_name):
|
||||
def parse(
|
||||
parser_mod_name: str,
|
||||
data: Union[str, Iterable[str]],
|
||||
quiet: Optional[bool] = False,
|
||||
raw: Optional[bool] = False,
|
||||
ignore_exceptions: Optional[bool] = None,
|
||||
**kwargs: Optional[Any]
|
||||
quiet: bool = False,
|
||||
raw: bool = False,
|
||||
ignore_exceptions: bool = None,
|
||||
**kwargs
|
||||
) -> Union[Dict, List[Dict], Iterator[Dict]]:
|
||||
"""
|
||||
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]
|
||||
|
||||
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.
|
||||
|
||||
@ -237,7 +237,7 @@ def parser_info(parser_mod_name: str) -> Dict:
|
||||
parser_mod = _get_parser(parser_mod_name)
|
||||
|
||||
if hasattr(parser_mod, 'info'):
|
||||
info_dict = {}
|
||||
info_dict: Dict = {}
|
||||
info_dict['name'] = parser_mod_name
|
||||
info_dict['argument'] = _parser_argument(parser_mod_name)
|
||||
parser_entry = vars(parser_mod.info)
|
||||
@ -251,7 +251,9 @@ def parser_info(parser_mod_name: str) -> 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.
|
||||
"""
|
||||
|
@ -39,7 +39,7 @@ Examples:
|
||||
[]
|
||||
"""
|
||||
import jc.utils
|
||||
from typing import Optional, List, Dict
|
||||
from typing import List, Dict
|
||||
|
||||
|
||||
class info():
|
||||
@ -81,8 +81,8 @@ def _process(proc_data: List[Dict]) -> List[Dict]:
|
||||
|
||||
def parse(
|
||||
data: str,
|
||||
raw: Optional[bool] = False,
|
||||
quiet: Optional[bool] = False
|
||||
raw: bool = False,
|
||||
quiet: bool = False
|
||||
) -> List[Dict]:
|
||||
"""
|
||||
Main text parsing function
|
||||
@ -100,7 +100,7 @@ def parse(
|
||||
jc.utils.compatibility(__name__, info.compatible, quiet)
|
||||
jc.utils.input_type_check(data)
|
||||
|
||||
raw_output = []
|
||||
raw_output: List = []
|
||||
|
||||
if jc.utils.has_data(data):
|
||||
|
||||
|
@ -49,7 +49,7 @@ Examples:
|
||||
{example output}
|
||||
...
|
||||
"""
|
||||
from typing import Optional, Dict, Iterable
|
||||
from typing import Dict, Iterable
|
||||
import jc.utils
|
||||
from jc.utils import stream_success, stream_error
|
||||
from jc.exceptions import ParseError
|
||||
@ -93,9 +93,9 @@ def _process(proc_data: Dict) -> Dict:
|
||||
|
||||
def parse(
|
||||
data: Iterable[str],
|
||||
raw: Optional[bool] = False,
|
||||
quiet: Optional[bool] = False,
|
||||
ignore_exceptions: Optional[bool] = False
|
||||
raw: bool = False,
|
||||
quiet: bool = False,
|
||||
ignore_exceptions: bool = False
|
||||
) -> Iterable[Dict]:
|
||||
"""
|
||||
Main text parsing generator function. Returns an iterator object.
|
||||
@ -121,7 +121,7 @@ def parse(
|
||||
jc.utils.streaming_input_type_check(data)
|
||||
|
||||
for line in data:
|
||||
output_line = {}
|
||||
output_line: Dict = {}
|
||||
try:
|
||||
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())
|
||||
|
||||
|
||||
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
|
||||
characters from strings.
|
||||
@ -157,7 +157,7 @@ def convert_to_int(value: Union[str, float]) -> int:
|
||||
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
|
||||
characters from strings.
|
||||
|
Reference in New Issue
Block a user