align lex_id code with readme

This commit is contained in:
Manuel Barkhau 2019-02-16 10:39:58 +01:00
parent ee68b1dd05
commit 687af6b2fb

View file

@ -102,10 +102,16 @@ def next_id(prev_id: str) -> str:
raise OverflowError("max lexical version reached: " + prev_id) raise OverflowError("max lexical version reached: " + prev_id)
_prev_id_val = int(prev_id, 10) _prev_id_val = int(prev_id, 10)
_next_id_val = int(_prev_id_val) + 1 _maybe_next_id_val = int(_prev_id_val) + 1
_next_id_str = f"{_next_id_val:0{num_digits}}" _maybe_next_id_str = f"{_maybe_next_id_val:0{num_digits}}"
if prev_id[0] != _next_id_str[0]:
_next_id_str = str(_next_id_val * 11) _is_padding_ok = prev_id[0] != _maybe_next_id_str[0]
_next_id_str: str
if _is_padding_ok:
_next_id_str = _maybe_next_id_str
else:
_next_id_str = str(_maybe_next_id_val * 11)
return _next_id_str return _next_id_str
@ -128,6 +134,7 @@ def ord_val(lex_id: str) -> int:
""" """
if len(lex_id) == 1: if len(lex_id) == 1:
return int(lex_id, 10) return int(lex_id, 10)
else:
return int(lex_id[1:], 10) return int(lex_id[1:], 10)