Repository: PrefectHQ/prefect

Issue:
Deprecation warning due to invalid escape sequences.
## Description

Deprecation warning due to invalid escape sequences. Using raw strings or escaping them again helps in resolving this. Check https://github.com/asottile/pyupgrade/ for automatic fix of this. This is tested on Python 3.8 but will happen on Python 3.7 too.

## Reproduction

```
find . -iname '*.py' | grep -Ev 'rdf4|tool' | xargs -P4 -I{} python3.8 -Wall -m py_compile {}
./src/prefect/environments/storage/docker.py:126: DeprecationWarning: invalid escape sequence \.
  if re.match("^[0-9]+\.[0-9]+\.[0-9]+$", self.prefect_version) != None:
./src/prefect/environments/storage/docker.py:396: DeprecationWarning: invalid escape sequence \ 
  env_vars = "ENV " + " \ \n{}".format(white_space).join(
./versioneer.py:433: DeprecationWarning: invalid escape sequence \s
  ] = '''
./tests/tasks/postgres/test_postgres.py:35: DeprecationWarning: invalid escape sequence \(
  match="The 'fetch' parameter must be one of the following - \('one', 'many', 'all'\)",
./tests/core/test_task.py:602: DeprecationWarning: invalid escape sequence \*
  UserWarning, match="all cache_\* options on a Task will be deprecated*"
./tests/core/test_task.py:607: DeprecationWarning: invalid escape sequence \*
  UserWarning, match="all cache_\* options on a Task will be deprecated*"
./tests/core/test_task.py:612: DeprecationWarning: invalid escape sequence \*
  UserWarning, match="all cache_\* options on a Task will be deprecated*"
./server/versioneer.py:433: DeprecationWarning: invalid escape sequence \s
  ] = '''
./server/tests/database/test_flow_traversal.py:20: DeprecationWarning: invalid escape sequence \ 
  """
./server/tests/database/test_flow_traversal.py:218: DeprecationWarning: invalid escape sequence \ 
  """
./build/lib/prefect/environments/storage/docker.py:126: DeprecationWarning: invalid escape sequence \.
  if re.match("^[0-9]+\.[0-9]+\.[0-9]+$", self.prefect_version) != None:
./build/lib/prefect/environments/storage/docker.py:396: DeprecationWarning: invalid escape sequence \ 
  env_vars = "ENV " + " \ \n{}".format(white_space).join(
```

## Environment

Python 3.8 on Ubuntu


Discussion:

Resolving patch:
diff --git a/server/versioneer.py b/server/versioneer.py
--- a/server/versioneer.py
+++ b/server/versioneer.py
@@ -415,7 +415,7 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, env=
             return None, None
     else:
         if verbose:
-            print("unable to find command, tried %s" % (commands,))
+            print("unable to find command, tried {}".format(commands))
         return None, None
     stdout = p.communicate()[0].strip()
     if sys.version_info[0] >= 3:
@@ -430,7 +430,7 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, env=
 
 LONG_VERSION_PY[
     "git"
-] = '''
+] = r'''
 # This file helps to compute a version number in source trees obtained from
 # git-archive tarball (such as those provided by githubs download-from-tag
 # feature). Distribution tarballs (built by setup.py sdist) and build
@@ -1001,11 +1001,11 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
         if verbose:
             print("keywords are unexpanded, not using")
         raise NotThisMethod("unexpanded keywords, not a git-archive tarball")
-    refs = set([r.strip() for r in refnames.strip("()").split(",")])
+    refs = {r.strip() for r in refnames.strip("()").split(",")}
     # starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of
     # just "foo-1.0". If we see a "tag: " prefix, prefer those.
     TAG = "tag: "
-    tags = set([r[len(TAG) :] for r in refs if r.startswith(TAG)])
+    tags = {r[len(TAG) :] for r in refs if r.startswith(TAG)}
     if not tags:
         # Either we're using git < 1.8.3, or there really are no tags. We use
         # a heuristic: assume all version tags have a digit. The old git %d
@@ -1014,7 +1014,7 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
         # between branches and tags. By ignoring refnames without digits, we
         # filter out many common branch names like "release" and
         # "stabilization", as well as "HEAD" and "master".
-        tags = set([r for r in refs if re.search(r"\d", r)])
+        tags = {r for r in refs if re.search(r"\d", r)}
         if verbose:
             print("discarding '%s', no digits" % ",".join(refs - tags))
     if verbose:
@@ -1117,9 +1117,8 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
             if verbose:
                 fmt = "tag '%s' doesn't start with prefix '%s'"
                 print(fmt % (full_tag, tag_prefix))
-            pieces["error"] = "tag '%s' doesn't start with prefix '%s'" % (
-                full_tag,
-                tag_prefix,
+            pieces["error"] = "tag '{}' doesn't start with prefix '{}'".format(
+                full_tag, tag_prefix,
             )
             return pieces
         pieces["closest-tag"] = full_tag[len(tag_prefix) :]
@@ -1258,7 +1257,7 @@ def write_to_version_file(filename, versions):
     with open(filename, "w") as f:
         f.write(SHORT_VERSION_PY % contents)
 
-    print("set %s to '%s'" % (filename, versions["version"]))
+    print("set {} to '{}'".format(filename, versions["version"]))
 
 
 def plus_or_dot(pieces):
@@ -1483,7 +1482,7 @@ def get_versions(verbose=False):
     try:
         ver = versions_from_file(versionfile_abs)
         if verbose:
-            print("got version from file %s %s" % (versionfile_abs, ver))
+            print("got version from file {} {}".format(versionfile_abs, ver))
         return ver
     except NotThisMethod:
         pass
diff --git a/src/prefect/environments/storage/docker.py b/src/prefect/environments/storage/docker.py
--- a/src/prefect/environments/storage/docker.py
+++ b/src/prefect/environments/storage/docker.py
@@ -123,7 +123,7 @@ def __init__(
             python_version = "{}.{}".format(
                 sys.version_info.major, sys.version_info.minor
             )
-            if re.match("^[0-9]+\.[0-9]+\.[0-9]+$", self.prefect_version) != None:
+            if re.match(r"^[0-9]+\.[0-9]+\.[0-9]+$", self.prefect_version) != None:
                 self.base_image = "prefecthq/prefect:{}-python{}".format(
                     self.prefect_version, python_version
                 )
@@ -393,7 +393,7 @@ def create_dockerfile_object(self, directory: str) -> str:
         env_vars = ""
         if self.env_vars:
             white_space = " " * 20
-            env_vars = "ENV " + " \ \n{}".format(white_space).join(
+            env_vars = "ENV " + " \\ \n{}".format(white_space).join(
                 "{k}={v}".format(k=k, v=v) for k, v in self.env_vars.items()
             )
 


Test patch:
diff --git a/server/tests/database/test_flow_traversal.py b/server/tests/database/test_flow_traversal.py
--- a/server/tests/database/test_flow_traversal.py
+++ b/server/tests/database/test_flow_traversal.py
@@ -17,7 +17,7 @@ def LiteralSetValue(value: list) -> str:
 
 @pytest.fixture(autouse=True)
 async def flow_id():
-    """
+    r"""
     1 -> 2 -> 3 -> 4 -> 5
             \              /
              7 -> 8 -> 9 -> 10
@@ -215,7 +215,7 @@ async def test_traverse_downstream_from_t8_and_t6_includes_t7(self, flow_id):
 
 
 class TestUpstreamTraversal:
-    """
+    r"""
     1 -> 2 -> 3 -> 4 -> 5
             \              /
              7 -> 8 -> 9 -> 10
diff --git a/tests/core/test_task.py b/tests/core/test_task.py
--- a/tests/core/test_task.py
+++ b/tests/core/test_task.py
@@ -314,15 +314,15 @@ def test_tags():
         Task(tags="test")
 
     t3 = Task(tags=["test", "test2", "test"])
-    assert t3.tags == set(["test", "test2"])
+    assert t3.tags == {"test", "test2"}
 
     with prefect.context(tags=["test"]):
         t4 = Task()
-        assert t4.tags == set(["test"])
+        assert t4.tags == {"test"}
 
     with prefect.context(tags=["test1", "test2"]):
         t5 = Task(tags=["test3"])
-        assert t5.tags == set(["test1", "test2", "test3"])
+        assert t5.tags == {"test1", "test2", "test3"}
 
 
 class TestInputsOutputs:
@@ -599,17 +599,17 @@ def test_task_check_mapped_args_are_subscriptable_in_advance(self):
 @pytest.mark.skip("Result handlers not yet deprecated")
 def test_cache_options_show_deprecation():
     with pytest.warns(
-        UserWarning, match="all cache_\* options on a Task will be deprecated*"
+        UserWarning, match=r"all cache_\* options on a Task will be deprecated*"
     ):
         Task(cache_for=object())
 
     with pytest.warns(
-        UserWarning, match="all cache_\* options on a Task will be deprecated*"
+        UserWarning, match=r"all cache_\* options on a Task will be deprecated*"
     ):
         Task(cache_validator=object())
 
     with pytest.warns(
-        UserWarning, match="all cache_\* options on a Task will be deprecated*"
+        UserWarning, match=r"all cache_\* options on a Task will be deprecated*"
     ):
         Task(cache_key=object())
 
diff --git a/tests/tasks/postgres/test_postgres.py b/tests/tasks/postgres/test_postgres.py
--- a/tests/tasks/postgres/test_postgres.py
+++ b/tests/tasks/postgres/test_postgres.py
@@ -32,6 +32,6 @@ def test_bad_fetch_param_raises(self):
         task = PostgresFetch(db_name="test", user="test", password="test", host="test")
         with pytest.raises(
             ValueError,
-            match="The 'fetch' parameter must be one of the following - \('one', 'many', 'all'\)",
+            match=r"The 'fetch' parameter must be one of the following - \('one', 'many', 'all'\)",
         ):
             task.run(query="SELECT * FROM some_table", fetch="not a valid parameter")