From ee7407cfe38b90dfe15e469a9b9f70996e29c70c Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Tue, 7 Jan 2020 21:57:34 -0800 Subject: [PATCH] Fix crash when licenseupdate.py can't find a '{year}' in .styleguide-license This gives __try_regex() the same behavior as __try_string_search(), which defaults the first year to the last year in the copyright range. --- wpiformat/wpiformat/licenseupdate.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/wpiformat/wpiformat/licenseupdate.py b/wpiformat/wpiformat/licenseupdate.py index b3f69cdb..e93c9d40 100644 --- a/wpiformat/wpiformat/licenseupdate.py +++ b/wpiformat/wpiformat/licenseupdate.py @@ -40,6 +40,8 @@ def __try_regex(self, lines, last_year, license_template): r"(?P[0-9]+)(-[0-9]+)?").replace("{padding}", "[ ]*") license_rgx = regex.compile(license_rgxstr, regex.M) + first_year = last_year + # Compare license match = license_rgx.search(lines) if match: @@ -51,7 +53,7 @@ def __try_regex(self, lines, last_year, license_template): # If comment at beginning of file is non-empty license, update it return (True, first_year, linesep + lines[match.end():].lstrip()) else: - return (False, last_year, lines) + return (False, first_year, lines) def __try_string_search(self, lines, last_year, license_template): """Try finding license with string search.