prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <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
  ```
  
  
  </issue>
  <code>
  [start of ddtrace/contrib/redis/patch.py]
  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 of ddtrace/contrib/redis/patch.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: 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
  
verification_info: {"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"}]}