From 5c7fa43e8af3e28fa2e1625a593b2ff2fa24cbd3 Mon Sep 17 00:00:00 2001
From: Anton Sarukhanov <code@ant.sr>
Date: Mon, 9 Dec 2019 23:16:30 -0500
Subject: [PATCH] Avoid duplicate no-leading-zero variants.

---
 whatformat/util/whatdateformat.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/whatformat/util/whatdateformat.py b/whatformat/util/whatdateformat.py
index 51022ef..41859f3 100644
--- a/whatformat/util/whatdateformat.py
+++ b/whatformat/util/whatdateformat.py
@@ -23,6 +23,7 @@ def get_all_format_strings(date_string, allow_reuse=False,
         parsed_datetime = parse(date_string)
     except ParserError:
         yield ''
+        return
     tokens = DATE_TOKEN_REGEX.findall(date_string)
     possible_matches = defaultdict(list)  # type: Dict[str, List[str]]
     for test_format in FORMAT_DIRECTIVES:
@@ -39,9 +40,9 @@ def get_all_format_strings(date_string, allow_reuse=False,
 
         possible_combinations = list(product(*possible_parts))
         for parts_sequence in possible_combinations:
-            if not no_zero and any(['%-' in x for x in parts_sequence]):
-                without_zero = [x.replace('%-', '%') for x in parts_sequence]
-                if without_zero in possible_combinations:
+            if any([bool('%-' in x) for x in parts_sequence]) and not no_zero:
+                if str(parts_sequence).replace('%-', '%') in \
+                        [str(c) for c in possible_combinations]:
                     continue
             if not allow_reuse:
                 counts = Counter(parts_sequence)
-- 
GitLab