Skip to content

Commit

Permalink
fix(mypy): avoid parsing redis asyncio files with Python 2 (#3868)
Browse files Browse the repository at this point in the history
## Description

Fixes #3845

## Checklist
- [ ] Title must conform to [conventional commit](https://github.com/conventional-changelog/commitlint/tree/master/%40commitlint/config-conventional).
- [ ] Add additional sections for `feat` and `fix` pull requests.
- [ ] Ensure tests are passing for affected code.
- [ ] [Library documentation](https://github.com/DataDog/dd-trace-py/tree/1.x/docs) and/or [Datadog's documentation site](https://github.com/DataDog/documentation/) is updated. Link to doc PR in description.

## Testing strategy

We do not as yet run Python 2 type checking so this will have to be tested manually.

## Reviewer Checklist
- [x] Title is accurate.
- [x] Description motivates each change.
- [x] No unnecessary changes were introduced in this PR.
- [x] PR cannot be broken up into smaller PRs.
- [x] Avoid breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes unless absolutely necessary.
- [x] Tests provided or description of manual testing performed is included in the code or PR.
- [x] Release note has been added for fixes and features, or else `changelog/no-changelog` label added.
- [x] All relevant GitHub issues are correctly linked.
- [x] Backports are identified and tagged with Mergifyio.
- [ ] Add to milestone.

(cherry picked from commit d2ed33a)
  • Loading branch information
majorgreys authored and mergify[bot] committed Jul 5, 2022
1 parent 48656a0 commit 9b03391
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ddtrace/contrib/redis/patch.py
@@ -1,4 +1,5 @@
import redis
from six import PY3

from ddtrace import config
from ddtrace.vendor import wrapt
Expand Down Expand Up @@ -36,7 +37,8 @@ def patch():
_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

Expand Down
1 change: 1 addition & 0 deletions docs/spelling_wordlist.txt
Expand Up @@ -107,6 +107,7 @@ mongoengine
multiline
multiprocess
multithreaded
mypy
mysql
mysqlclient
mysqldb
Expand Down
4 changes: 4 additions & 0 deletions releasenotes/notes/fix-mypy-py2-redis-4c8d3b4e461c6074.yaml
@@ -0,0 +1,4 @@
---
fixes:
- |
mypy: Avoid parsing redis asyncio files when type checking Python 2

0 comments on commit 9b03391

Please sign in to comment.