We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
mypy invalid syntax error with python 2
### Which version of dd-trace-py are you using?

v1.2.0

### Which version of pip are you using?

22.1.2

### Which version of the libraries are you using?

```
ddtrace==1.2.0
mypy[python2]==0.961
```

### How can we reproduce your problem?

1. Clone https://gist.github.com/majorgreys/720201c4bdd33131e4c231207ef716ce
2. Run `docker run --rm -it (docker build .)`

### What is the result that you get?

```
usr/local/lib/python3.9/site-packages/ddtrace/contrib/redis/asyncio_patch.py:12: error: invalid syntax
Found 1 error in 1 file (errors prevented further checking)
```

### What is the result that you expected?

```
Success: no issues found in 1 source file
```


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `ddtrace/contrib/redis/patch.py`
Content:
```
1 import redis
2 
3 from ddtrace import config
4 from ddtrace.vendor import wrapt
5 
6 from ...internal.utils.formats import stringify_cache_args
7 from ...pin import Pin
8 from ..trace_utils import unwrap
9 from .util import _trace_redis_cmd
10 from .util import _trace_redis_execute_pipeline
11 
12 
13 config._add("redis", dict(_default_service="redis"))
14 
15 
16 def patch():
17     """Patch the instrumented methods
18 
19     This duplicated doesn't look nice. The nicer alternative is to use an ObjectProxy on top
20     of Redis and StrictRedis. However, it means that any "import redis.Redis" won't be instrumented.
21     """
22     if getattr(redis, "_datadog_patch", False):
23         return
24     setattr(redis, "_datadog_patch", True)
25 
26     _w = wrapt.wrap_function_wrapper
27 
28     if redis.VERSION < (3, 0, 0):
29         _w("redis", "StrictRedis.execute_command", traced_execute_command)
30         _w("redis", "StrictRedis.pipeline", traced_pipeline)
31         _w("redis", "Redis.pipeline", traced_pipeline)
32         _w("redis.client", "BasePipeline.execute", traced_execute_pipeline)
33         _w("redis.client", "BasePipeline.immediate_execute_command", traced_execute_command)
34     else:
35         _w("redis", "Redis.execute_command", traced_execute_command)
36         _w("redis", "Redis.pipeline", traced_pipeline)
37         _w("redis.client", "Pipeline.execute", traced_execute_pipeline)
38         _w("redis.client", "Pipeline.immediate_execute_command", traced_execute_command)
39         if redis.VERSION >= (4, 2, 0):
40             from .asyncio_patch import traced_async_execute_command
41             from .asyncio_patch import traced_async_execute_pipeline
42 
43             _w("redis.asyncio.client", "Redis.execute_command", traced_async_execute_command)
44             _w("redis.asyncio.client", "Redis.pipeline", traced_pipeline)
45             _w("redis.asyncio.client", "Pipeline.execute", traced_async_execute_pipeline)
46             _w("redis.asyncio.client", "Pipeline.immediate_execute_command", traced_async_execute_command)
47             Pin(service=None).onto(redis.asyncio.Redis)
48     Pin(service=None).onto(redis.StrictRedis)
49 
50 
51 def unpatch():
52     if getattr(redis, "_datadog_patch", False):
53         setattr(redis, "_datadog_patch", False)
54 
55         if redis.VERSION < (3, 0, 0):
56             unwrap(redis.StrictRedis, "execute_command")
57             unwrap(redis.StrictRedis, "pipeline")
58             unwrap(redis.Redis, "pipeline")
59             unwrap(redis.client.BasePipeline, "execute")
60             unwrap(redis.client.BasePipeline, "immediate_execute_command")
61         else:
62             unwrap(redis.Redis, "execute_command")
63             unwrap(redis.Redis, "pipeline")
64             unwrap(redis.client.Pipeline, "execute")
65             unwrap(redis.client.Pipeline, "immediate_execute_command")
66             if redis.VERSION >= (4, 2, 0):
67                 unwrap(redis.asyncio.client.Redis, "execute_command")
68                 unwrap(redis.asyncio.client.Redis, "pipeline")
69                 unwrap(redis.asyncio.client.Pipeline, "execute")
70                 unwrap(redis.asyncio.client.Pipeline, "immediate_execute_command")
71 
72 
73 #
74 # tracing functions
75 #
76 def traced_execute_command(func, instance, args, kwargs):
77     pin = Pin.get_from(instance)
78     if not pin or not pin.enabled():
79         return func(*args, **kwargs)
80 
81     with _trace_redis_cmd(pin, config.redis, instance, args):
82         return func(*args, **kwargs)
83 
84 
85 def traced_pipeline(func, instance, args, kwargs):
86     pipeline = func(*args, **kwargs)
87     pin = Pin.get_from(instance)
88     if pin:
89         pin.onto(pipeline)
90     return pipeline
91 
92 
93 def traced_execute_pipeline(func, instance, args, kwargs):
94     pin = Pin.get_from(instance)
95     if not pin or not pin.enabled():
96         return func(*args, **kwargs)
97 
98     cmds = [stringify_cache_args(c) for c, _ in instance.command_stack]
99     resource = "\n".join(cmds)
100     with _trace_redis_execute_pipeline(pin, config.redis, resource, instance):
101         return func(*args, **kwargs)
102
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/ddtrace/contrib/redis/patch.py b/ddtrace/contrib/redis/patch.py
--- a/ddtrace/contrib/redis/patch.py
+++ b/ddtrace/contrib/redis/patch.py
@@ -1,4 +1,5 @@
 import redis
+from six import PY3
 
 from ddtrace import config
 from ddtrace.vendor import wrapt
@@ -36,7 +37,8 @@
         _w("redis", "Redis.pipeline", traced_pipeline)
         _w("redis.client", "Pipeline.execute", traced_execute_pipeline)
         _w("redis.client", "Pipeline.immediate_execute_command", traced_execute_command)
-        if redis.VERSION >= (4, 2, 0):
+        # Avoid mypy invalid syntax errors when parsing Python 2 files
+        if PY3 and redis.VERSION >= (4, 2, 0):
             from .asyncio_patch import traced_async_execute_command
             from .asyncio_patch import traced_async_execute_pipeline

{"golden_diff": "diff --git a/ddtrace/contrib/redis/patch.py b/ddtrace/contrib/redis/patch.py\n--- a/ddtrace/contrib/redis/patch.py\n+++ b/ddtrace/contrib/redis/patch.py\n@@ -1,4 +1,5 @@\n import redis\n+from six import PY3\n \n from ddtrace import config\n from ddtrace.vendor import wrapt\n@@ -36,7 +37,8 @@\n         _w(\"redis\", \"Redis.pipeline\", traced_pipeline)\n         _w(\"redis.client\", \"Pipeline.execute\", traced_execute_pipeline)\n         _w(\"redis.client\", \"Pipeline.immediate_execute_command\", traced_execute_command)\n-        if redis.VERSION >= (4, 2, 0):\n+        # Avoid mypy invalid syntax errors when parsing Python 2 files\n+        if PY3 and redis.VERSION >= (4, 2, 0):\n             from .asyncio_patch import traced_async_execute_command\n             from .asyncio_patch import traced_async_execute_pipeline\n", "issue": "mypy invalid syntax error with python 2\n### Which version of dd-trace-py are you using?\r\n\r\nv1.2.0\r\n\r\n### Which version of pip are you using?\r\n\r\n22.1.2\r\n\r\n### Which version of the libraries are you using?\r\n\r\n```\r\nddtrace==1.2.0\r\nmypy[python2]==0.961\r\n```\r\n\r\n### How can we reproduce your problem?\r\n\r\n1. Clone https://gist.github.com/majorgreys/720201c4bdd33131e4c231207ef716ce\r\n2. Run `docker run --rm -it (docker build .)`\r\n\r\n### What is the result that you get?\r\n\r\n```\r\nusr/local/lib/python3.9/site-packages/ddtrace/contrib/redis/asyncio_patch.py:12: error: invalid syntax\r\nFound 1 error in 1 file (errors prevented further checking)\r\n```\r\n\r\n### What is the result that you expected?\r\n\r\n```\r\nSuccess: no issues found in 1 source file\r\n```\r\n\n", "before_files": [{"content": "import redis\n\nfrom ddtrace import config\nfrom ddtrace.vendor import wrapt\n\nfrom ...internal.utils.formats import stringify_cache_args\nfrom ...pin import Pin\nfrom ..trace_utils import unwrap\nfrom .util import _trace_redis_cmd\nfrom .util import _trace_redis_execute_pipeline\n\n\nconfig._add(\"redis\", dict(_default_service=\"redis\"))\n\n\ndef patch():\n    \"\"\"Patch the instrumented methods\n\n    This duplicated doesn't look nice. The nicer alternative is to use an ObjectProxy on top\n    of Redis and StrictRedis. However, it means that any \"import redis.Redis\" won't be instrumented.\n    \"\"\"\n    if getattr(redis, \"_datadog_patch\", False):\n        return\n    setattr(redis, \"_datadog_patch\", True)\n\n    _w = wrapt.wrap_function_wrapper\n\n    if redis.VERSION < (3, 0, 0):\n        _w(\"redis\", \"StrictRedis.execute_command\", traced_execute_command)\n        _w(\"redis\", \"StrictRedis.pipeline\", traced_pipeline)\n        _w(\"redis\", \"Redis.pipeline\", traced_pipeline)\n        _w(\"redis.client\", \"BasePipeline.execute\", traced_execute_pipeline)\n        _w(\"redis.client\", \"BasePipeline.immediate_execute_command\", traced_execute_command)\n    else:\n        _w(\"redis\", \"Redis.execute_command\", traced_execute_command)\n        _w(\"redis\", \"Redis.pipeline\", traced_pipeline)\n        _w(\"redis.client\", \"Pipeline.execute\", traced_execute_pipeline)\n        _w(\"redis.client\", \"Pipeline.immediate_execute_command\", traced_execute_command)\n        if redis.VERSION >= (4, 2, 0):\n            from .asyncio_patch import traced_async_execute_command\n            from .asyncio_patch import traced_async_execute_pipeline\n\n            _w(\"redis.asyncio.client\", \"Redis.execute_command\", traced_async_execute_command)\n            _w(\"redis.asyncio.client\", \"Redis.pipeline\", traced_pipeline)\n            _w(\"redis.asyncio.client\", \"Pipeline.execute\", traced_async_execute_pipeline)\n            _w(\"redis.asyncio.client\", \"Pipeline.immediate_execute_command\", traced_async_execute_command)\n            Pin(service=None).onto(redis.asyncio.Redis)\n    Pin(service=None).onto(redis.StrictRedis)\n\n\ndef unpatch():\n    if getattr(redis, \"_datadog_patch\", False):\n        setattr(redis, \"_datadog_patch\", False)\n\n        if redis.VERSION < (3, 0, 0):\n            unwrap(redis.StrictRedis, \"execute_command\")\n            unwrap(redis.StrictRedis, \"pipeline\")\n            unwrap(redis.Redis, \"pipeline\")\n            unwrap(redis.client.BasePipeline, \"execute\")\n            unwrap(redis.client.BasePipeline, \"immediate_execute_command\")\n        else:\n            unwrap(redis.Redis, \"execute_command\")\n            unwrap(redis.Redis, \"pipeline\")\n            unwrap(redis.client.Pipeline, \"execute\")\n            unwrap(redis.client.Pipeline, \"immediate_execute_command\")\n            if redis.VERSION >= (4, 2, 0):\n                unwrap(redis.asyncio.client.Redis, \"execute_command\")\n                unwrap(redis.asyncio.client.Redis, \"pipeline\")\n                unwrap(redis.asyncio.client.Pipeline, \"execute\")\n                unwrap(redis.asyncio.client.Pipeline, \"immediate_execute_command\")\n\n\n#\n# tracing functions\n#\ndef traced_execute_command(func, instance, args, kwargs):\n    pin = Pin.get_from(instance)\n    if not pin or not pin.enabled():\n        return func(*args, **kwargs)\n\n    with _trace_redis_cmd(pin, config.redis, instance, args):\n        return func(*args, **kwargs)\n\n\ndef traced_pipeline(func, instance, args, kwargs):\n    pipeline = func(*args, **kwargs)\n    pin = Pin.get_from(instance)\n    if pin:\n        pin.onto(pipeline)\n    return pipeline\n\n\ndef traced_execute_pipeline(func, instance, args, kwargs):\n    pin = Pin.get_from(instance)\n    if not pin or not pin.enabled():\n        return func(*args, **kwargs)\n\n    cmds = [stringify_cache_args(c) for c, _ in instance.command_stack]\n    resource = \"\\n\".join(cmds)\n    with _trace_redis_execute_pipeline(pin, config.redis, resource, instance):\n        return func(*args, **kwargs)\n", "path": "ddtrace/contrib/redis/patch.py"}], "after_files": [{"content": "import redis\nfrom six import PY3\n\nfrom ddtrace import config\nfrom ddtrace.vendor import wrapt\n\nfrom ...internal.utils.formats import stringify_cache_args\nfrom ...pin import Pin\nfrom ..trace_utils import unwrap\nfrom .util import _trace_redis_cmd\nfrom .util import _trace_redis_execute_pipeline\n\n\nconfig._add(\"redis\", dict(_default_service=\"redis\"))\n\n\ndef patch():\n    \"\"\"Patch the instrumented methods\n\n    This duplicated doesn't look nice. The nicer alternative is to use an ObjectProxy on top\n    of Redis and StrictRedis. However, it means that any \"import redis.Redis\" won't be instrumented.\n    \"\"\"\n    if getattr(redis, \"_datadog_patch\", False):\n        return\n    setattr(redis, \"_datadog_patch\", True)\n\n    _w = wrapt.wrap_function_wrapper\n\n    if redis.VERSION < (3, 0, 0):\n        _w(\"redis\", \"StrictRedis.execute_command\", traced_execute_command)\n        _w(\"redis\", \"StrictRedis.pipeline\", traced_pipeline)\n        _w(\"redis\", \"Redis.pipeline\", traced_pipeline)\n        _w(\"redis.client\", \"BasePipeline.execute\", traced_execute_pipeline)\n        _w(\"redis.client\", \"BasePipeline.immediate_execute_command\", traced_execute_command)\n    else:\n        _w(\"redis\", \"Redis.execute_command\", traced_execute_command)\n        _w(\"redis\", \"Redis.pipeline\", traced_pipeline)\n        _w(\"redis.client\", \"Pipeline.execute\", traced_execute_pipeline)\n        _w(\"redis.client\", \"Pipeline.immediate_execute_command\", traced_execute_command)\n        # Avoid mypy invalid syntax errors when parsing Python 2 files\n        if PY3 and redis.VERSION >= (4, 2, 0):\n            from .asyncio_patch import traced_async_execute_command\n            from .asyncio_patch import traced_async_execute_pipeline\n\n            _w(\"redis.asyncio.client\", \"Redis.execute_command\", traced_async_execute_command)\n            _w(\"redis.asyncio.client\", \"Redis.pipeline\", traced_pipeline)\n            _w(\"redis.asyncio.client\", \"Pipeline.execute\", traced_async_execute_pipeline)\n            _w(\"redis.asyncio.client\", \"Pipeline.immediate_execute_command\", traced_async_execute_command)\n            Pin(service=None).onto(redis.asyncio.Redis)\n    Pin(service=None).onto(redis.StrictRedis)\n\n\ndef unpatch():\n    if getattr(redis, \"_datadog_patch\", False):\n        setattr(redis, \"_datadog_patch\", False)\n\n        if redis.VERSION < (3, 0, 0):\n            unwrap(redis.StrictRedis, \"execute_command\")\n            unwrap(redis.StrictRedis, \"pipeline\")\n            unwrap(redis.Redis, \"pipeline\")\n            unwrap(redis.client.BasePipeline, \"execute\")\n            unwrap(redis.client.BasePipeline, \"immediate_execute_command\")\n        else:\n            unwrap(redis.Redis, \"execute_command\")\n            unwrap(redis.Redis, \"pipeline\")\n            unwrap(redis.client.Pipeline, \"execute\")\n            unwrap(redis.client.Pipeline, \"immediate_execute_command\")\n            if redis.VERSION >= (4, 2, 0):\n                unwrap(redis.asyncio.client.Redis, \"execute_command\")\n                unwrap(redis.asyncio.client.Redis, \"pipeline\")\n                unwrap(redis.asyncio.client.Pipeline, \"execute\")\n                unwrap(redis.asyncio.client.Pipeline, \"immediate_execute_command\")\n\n\n#\n# tracing functions\n#\ndef traced_execute_command(func, instance, args, kwargs):\n    pin = Pin.get_from(instance)\n    if not pin or not pin.enabled():\n        return func(*args, **kwargs)\n\n    with _trace_redis_cmd(pin, config.redis, instance, args):\n        return func(*args, **kwargs)\n\n\ndef traced_pipeline(func, instance, args, kwargs):\n    pipeline = func(*args, **kwargs)\n    pin = Pin.get_from(instance)\n    if pin:\n        pin.onto(pipeline)\n    return pipeline\n\n\ndef traced_execute_pipeline(func, instance, args, kwargs):\n    pin = Pin.get_from(instance)\n    if not pin or not pin.enabled():\n        return func(*args, **kwargs)\n\n    cmds = [stringify_cache_args(c) for c, _ in instance.command_stack]\n    resource = \"\\n\".join(cmds)\n    with _trace_redis_execute_pipeline(pin, config.redis, resource, instance):\n        return func(*args, **kwargs)\n", "path": "ddtrace/contrib/redis/patch.py"}]}