Skip to content

Commit 6ee245f

Browse files
committed
Run flake8 with Python 3
This allows to remove a few noqa flag from files using `yield from` and fixing various errors. The compat tests have been merged to a single scenario that works for both Python version in order to make flake8 happier. Some wild noqa tag have been replaced by specific flake8 error code ignore tag so avoid skipping non-wanted mistakes.
1 parent 6321d3c commit 6ee245f

File tree

29 files changed

+140
-207
lines changed

29 files changed

+140
-207
lines changed

ddtrace/bootstrap/sitecustomize.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818

1919
if logs_injection:
2020
# immediately patch logging if trace id injected
21-
from ddtrace import patch; patch(logging=True) # noqa
21+
from ddtrace import patch
22+
patch(logging=True)
2223

2324
debug = os.environ.get('DATADOG_TRACE_DEBUG')
2425

@@ -108,7 +109,8 @@ def add_global_tags(tracer):
108109

109110
if patch:
110111
update_patched_modules()
111-
from ddtrace import patch_all; patch_all(**EXTRA_PATCHED_MODULES) # noqa
112+
from ddtrace import patch_all
113+
patch_all(**EXTRA_PATCHED_MODULES)
112114

113115
debug = os.environ.get('DATADOG_TRACE_DEBUG')
114116
if debug and debug.lower() == 'true':
@@ -143,6 +145,6 @@ def add_global_tags(tracer):
143145
# properly loaded without exceptions. This must be the last action in the module
144146
# when the execution ends with a success.
145147
loaded = True
146-
except Exception as e:
148+
except Exception:
147149
loaded = False
148150
log.warn('error configuring Datadog tracing', exc_info=True)

ddtrace/commands/ddtrace_run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
(e.g. pylons, flask, django)
3535
For tracing without a web integration, prefer setting the service name in code.
3636
DATADOG_PRIORITY_SAMPLING=true|false : (default: false): enables Priority Sampling.
37-
""" # noqa
37+
""" # noqa: E501
3838

3939

4040
def _ddtrace_root():

ddtrace/contrib/aiobotocore/patch.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def read(self, *args, **kwargs):
4949
span.span_type = self._self_parent_span.span_type
5050
span.meta = dict(self._self_parent_span.meta)
5151

52-
result = yield from self.__wrapped__.read(*args, **kwargs) # noqa: E999
52+
result = yield from self.__wrapped__.read(*args, **kwargs)
5353
span.set_tag('Length', len(result))
5454

5555
return result
@@ -72,7 +72,7 @@ def __aexit__(self, *args, **kwargs):
7272
def _wrapped_api_call(original_func, instance, args, kwargs):
7373
pin = Pin.get_from(instance)
7474
if not pin or not pin.enabled():
75-
result = yield from original_func(*args, **kwargs) # noqa: E999
75+
result = yield from original_func(*args, **kwargs)
7676
return result
7777

7878
endpoint_name = deep_getattr(instance, '_endpoint._endpoint_prefix')
@@ -99,7 +99,7 @@ def _wrapped_api_call(original_func, instance, args, kwargs):
9999
}
100100
span.set_tags(meta)
101101

102-
result = yield from original_func(*args, **kwargs) # noqa: E999
102+
result = yield from original_func(*args, **kwargs)
103103

104104
body = result.get('Body')
105105
if isinstance(body, ClientResponseContentProxy):

ddtrace/contrib/aiohttp/middlewares.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def attach_context(request):
6060
request[REQUEST_CONTEXT_KEY] = request_span.context
6161
request[REQUEST_SPAN_KEY] = request_span
6262
try:
63-
response = yield from handler(request) # noqa: E999
63+
response = yield from handler(request)
6464
return response
6565
except Exception:
6666
request_span.set_traceback()

ddtrace/contrib/aiopg/connection.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def __init__(self, cursor, pin):
2323
def _trace_method(self, method, resource, extra_tags, *args, **kwargs):
2424
pin = Pin.get_from(self)
2525
if not pin or not pin.enabled():
26-
result = yield from method(*args, **kwargs) # noqa: E999
26+
result = yield from method(*args, **kwargs)
2727
return result
2828
service = pin.service
2929

@@ -44,15 +44,15 @@ def _trace_method(self, method, resource, extra_tags, *args, **kwargs):
4444
result = yield from method(*args, **kwargs)
4545
return result
4646
finally:
47-
s.set_metric("db.rowcount", self.rowcount)
47+
s.set_metric('db.rowcount', self.rowcount)
4848

4949
@asyncio.coroutine
5050
def executemany(self, query, *args, **kwargs):
5151
# FIXME[matt] properly handle kwargs here. arg names can be different
5252
# with different libs.
5353
result = yield from self._trace_method(
5454
self.__wrapped__.executemany, query, {'sql.executemany': 'true'},
55-
query, *args, **kwargs) # noqa: E999
55+
query, *args, **kwargs)
5656
return result
5757

5858
@asyncio.coroutine
@@ -64,7 +64,7 @@ def execute(self, query, *args, **kwargs):
6464
@asyncio.coroutine
6565
def callproc(self, proc, args):
6666
result = yield from self._trace_method(
67-
self.__wrapped__.callproc, proc, {}, proc, args) # noqa: E999
67+
self.__wrapped__.callproc, proc, {}, proc, args)
6868
return result
6969

7070

@@ -88,7 +88,7 @@ def cursor(self, *args, **kwargs):
8888

8989
@asyncio.coroutine
9090
def _cursor(self, *args, **kwargs):
91-
cursor = yield from self.__wrapped__._cursor(*args, **kwargs) # noqa: E999
91+
cursor = yield from self.__wrapped__._cursor(*args, **kwargs)
9292
pin = Pin.get_from(self)
9393
if not pin:
9494
return cursor

ddtrace/contrib/aiopg/patch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def unpatch():
3232

3333
@asyncio.coroutine
3434
def patched_connect(connect_func, _, args, kwargs):
35-
conn = yield from connect_func(*args, **kwargs) # noqa: E999
35+
conn = yield from connect_func(*args, **kwargs)
3636
return psycppg_patch_conn(conn, traced_conn_cls=AIOTracedConnection)
3737

3838

ddtrace/contrib/asyncio/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def set_call_context(task, ctx):
2525
setattr(task, CONTEXT_ATTR, ctx)
2626

2727

28-
def ensure_future(coro_or_future, *, loop=None, tracer=None): # noqa: E999
28+
def ensure_future(coro_or_future, *, loop=None, tracer=None):
2929
"""
3030
Wrapper for the asyncio.ensure_future() function that
3131
sets a context to the newly created Task. If the current

tests/contrib/aiobotocore/py35/test.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# flake8: noqa
2-
# DEV: Skip linting, we lint with Python 2, we'll get SyntaxErrors from `async`
31
import aiobotocore
42

53
from ddtrace.contrib.aiobotocore.patch import patch, unpatch
@@ -37,7 +35,7 @@ async def test_response_context_manager(self):
3735

3836
traces = self.tracer.writer.pop_traces()
3937

40-
version = aiobotocore.__version__.split(".")
38+
version = aiobotocore.__version__.split('.')
4139
pre_08 = int(version[0]) == 0 and int(version[1]) < 8
4240
# Version 0.8+ generates only one span for reading an object.
4341
if pre_08:

tests/contrib/aiobotocore/test.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# flake8: noqa
2-
# DEV: Skip linting, we lint with Python 2, we'll get SyntaxErrors from `yield from`
31
import aiobotocore
42
from botocore.errorfactory import ClientError
53

@@ -126,7 +124,7 @@ def test_s3_client_read(self):
126124
yield from response['Body'].read()
127125

128126
traces = self.tracer.writer.pop_traces()
129-
version = aiobotocore.__version__.split(".")
127+
version = aiobotocore.__version__.split('.')
130128
pre_08 = int(version[0]) == 0 and int(version[1]) < 8
131129
if pre_08:
132130
self.assertEqual(len(traces), 2)
@@ -247,7 +245,7 @@ def test_opentraced_client(self):
247245

248246
with ot_tracer.start_active_span('ot_outer_span'):
249247
with aiobotocore_client('ec2', self.tracer) as ec2:
250-
yield from ec2.describe_instances()
248+
yield from ec2.describe_instances()
251249

252250
traces = self.tracer.writer.pop_traces()
253251
print(traces)

tests/contrib/aiohttp/app/web.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# flake8: noqa
21
import os
32
import jinja2
43
import asyncio
@@ -61,6 +60,7 @@ def route_sub_span(request):
6160
span.set_tag('sub_span', 'true')
6261
return web.Response(text='OK')
6362

63+
6464
@asyncio.coroutine
6565
def coro_2(request):
6666
tracer = get_tracer(request)

0 commit comments

Comments
 (0)