From 1dbe1308464cbfbf85c4a6799aa4a7687f7a039f Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Wed, 25 Sep 2024 15:08:00 -0400 Subject: [PATCH 1/3] Fix SyntaxError in re.compile() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Replaces string literal with a raw string * https://docs.python.org/3/library/re.html#module-re states: [..] any invalid escape sequences in Python’s usage of the backslash in string literals now generate a SyntaxWarning and in the future this will become a SyntaxError. The solution is to use Python's raw string notation for regular expression patterns. --- crds/certify/certify.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crds/certify/certify.py b/crds/certify/certify.py index 8197c59ad..eb4076028 100644 --- a/crds/certify/certify.py +++ b/crds/certify/certify.py @@ -687,7 +687,7 @@ def load(self): class AsdfCertifier(ReferenceCertifier): """Certifier for ADSF type, invoke data models checks.""" - _VERSION_RE = re.compile(f"^[0-9]+\.[0-9]+\.[0-9]+$") + _VERSION_RE = re.compile(r"^[0-9]+\.[0-9]+\.[0-9]+$") def certify(self): """Certify an unknown format file.""" From 9e6c8efd0265c1f402a1af152889e501268a3756 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Wed, 25 Sep 2024 15:26:47 -0400 Subject: [PATCH 2/3] Replace more literal strings with raw strings --- crds/certify/validators/synphot.py | 2 +- crds/core/timestamp.py | 2 +- crds/hst/siname.py | 2 +- crds/submit/submit.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crds/certify/validators/synphot.py b/crds/certify/validators/synphot.py index e6b05b7e5..63466484a 100644 --- a/crds/certify/validators/synphot.py +++ b/crds/certify/validators/synphot.py @@ -179,7 +179,7 @@ def _check_component_filename(context, reftype, suffix, filename, header): log.error("Header missing COMPNAME, unable to certify filename") return False - pattern = re.compile(".*_([0-9]{3})_" + suffix + ".fits") + pattern = re.compile(r".*_([0-9]{3})_" + suffix + r".fits") match = pattern.match(os.path.basename(filename)) if not match: diff --git a/crds/core/timestamp.py b/crds/core/timestamp.py index fd39a9570..28bf87277 100644 --- a/crds/core/timestamp.py +++ b/crds/core/timestamp.py @@ -291,7 +291,7 @@ def parse_numerical_date(dstr): class DateParser: """Abstract baseclass for defining date parsers.""" - format = re.compile("^$") + format = re.compile(r"^$") should_be = "DATE FORMAT NOT DEFINED" @classmethod diff --git a/crds/hst/siname.py b/crds/hst/siname.py index 48840a6f1..44f718065 100644 --- a/crds/hst/siname.py +++ b/crds/hst/siname.py @@ -36,7 +36,7 @@ class UnknownCDBSPrefix(Exception): pass # global compiled regex for splitting filenames -filesplit = re.compile("[_\.]") +filesplit = re.compile(r"[_\.]") # post-SM2 instruments supported by CDBS CDBS_supports = ("ACS","STIS","NICMOS","WFPC2","WFC3","COS") diff --git a/crds/submit/submit.py b/crds/submit/submit.py index f317b22bc..e167d2dab 100644 --- a/crds/submit/submit.py +++ b/crds/submit/submit.py @@ -360,7 +360,7 @@ def find_new_rmaps(self, old_maps, new_maps): return rnew def get_renamed_rmaps(self, soup, fmap): - diffs = soup.find_all(string=re.compile("Logical Diff")) + diffs = soup.find_all(string=re.compile(r"Logical Diff")) if len(diffs) > 0: for diff in diffs: d = diff.split('(')[-1].split(')')[0] From eb4cede8a4957827881bc3e96c8793f516fa3984 Mon Sep 17 00:00:00 2001 From: alphasentaurii Date: Tue, 15 Oct 2024 10:08:20 -0400 Subject: [PATCH 3/3] added news fragment --- changes/1077.general.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 changes/1077.general.rst diff --git a/changes/1077.general.rst b/changes/1077.general.rst new file mode 100644 index 000000000..515a52d49 --- /dev/null +++ b/changes/1077.general.rst @@ -0,0 +1 @@ +replaces deprecated string literals with raw strings in regex pattern matching