typing - avoid variable reuse with differen ttype

This commit is contained in:
xmatthias 2018-05-31 21:22:46 +02:00
parent 2976a50c58
commit c0cef7250d

View File

@ -19,7 +19,7 @@ class Arguments(object):
def __init__(self, args: List[str], description: str) -> None: def __init__(self, args: List[str], description: str) -> None:
self.args = args self.args = args
self.parsed_arg = None self.parsed_arg: Optional[argparse.Namespace] = None
self.parser = argparse.ArgumentParser(description=description) self.parser = argparse.ArgumentParser(description=description)
def _load_args(self) -> None: def _load_args(self) -> None:
@ -211,7 +211,7 @@ class Arguments(object):
self.hyperopt_options(hyperopt_cmd) self.hyperopt_options(hyperopt_cmd)
@staticmethod @staticmethod
def parse_timerange(text: str) -> Optional[Tuple[List, int, int]]: def parse_timerange(text: str) -> Optional[Tuple[Tuple, Optional[int], Optional[int]]]:
""" """
Parse the value of the argument --timerange to determine what is the range desired Parse the value of the argument --timerange to determine what is the range desired
:param text: value from --timerange :param text: value from --timerange
@ -231,21 +231,21 @@ class Arguments(object):
if match: # Regex has matched if match: # Regex has matched
rvals = match.groups() rvals = match.groups()
index = 0 index = 0
start = None start: Optional[int] = None
stop = None stop: Optional[int] = None
if stype[0]: if stype[0]:
start = rvals[index] starts = rvals[index]
if stype[0] == 'date': if stype[0] == 'date':
start = arrow.get(start, 'YYYYMMDD').timestamp start = arrow.get(starts, 'YYYYMMDD').timestamp
else: else:
start = int(start) start = int(starts)
index += 1 index += 1
if stype[1]: if stype[1]:
stop = rvals[index] stops = rvals[index]
if stype[1] == 'date': if stype[1] == 'date':
stop = arrow.get(stop, 'YYYYMMDD').timestamp stop = arrow.get(stops, 'YYYYMMDD').timestamp
else: else:
stop = int(stop) stop = int(stops)
return stype, start, stop return stype, start, stop
raise Exception('Incorrect syntax for timerange "%s"' % text) raise Exception('Incorrect syntax for timerange "%s"' % text)