Skip to content

Commit cc7a11c

Browse files
jdKyle-Verhoog
authored andcommitted
Upgrade flake8 to 3.8 + black ddtrace{,.span} (#1429)
* chore: upgrade flake8 to 3.8 and fix new warnings * chore(black): black ddtrace and ddtrace.span
1 parent f52852c commit cc7a11c

File tree

8 files changed

+84
-80
lines changed

8 files changed

+84
-80
lines changed

ddtrace/__init__.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
# Always import and patch import hooks before loading anything else
44
from .internal.import_hooks import patch as patch_import_hooks
5+
56
patch_import_hooks() # noqa: E402
67

7-
from .monkey import patch, patch_all
8-
from .pin import Pin
9-
from .span import Span
10-
from .tracer import Tracer
11-
from .settings import config
12-
from .utils.deprecation import deprecated
8+
from .monkey import patch, patch_all # noqa: E402
9+
from .pin import Pin # noqa: E402
10+
from .span import Span # noqa: E402
11+
from .tracer import Tracer # noqa: E402
12+
from .settings import config # noqa: E402
13+
from .utils.deprecation import deprecated # noqa: E402
1314

1415
try:
1516
__version__ = pkg_resources.get_distribution(__name__).version
@@ -22,21 +23,21 @@
2223
tracer = Tracer()
2324

2425
__all__ = [
25-
'patch',
26-
'patch_all',
27-
'Pin',
28-
'Span',
29-
'tracer',
30-
'Tracer',
31-
'config',
26+
"patch",
27+
"patch_all",
28+
"Pin",
29+
"Span",
30+
"tracer",
31+
"Tracer",
32+
"config",
3233
]
3334

3435

35-
@deprecated('This method will be removed altogether', '1.0.0')
36+
@deprecated("This method will be removed altogether", "1.0.0")
3637
def install_excepthook():
3738
"""Install a hook that intercepts unhandled exception and send metrics about them."""
3839

3940

40-
@deprecated('This method will be removed altogether', '1.0.0')
41+
@deprecated("This method will be removed altogether", "1.0.0")
4142
def uninstall_excepthook():
4243
"""Uninstall the global tracer except hook."""

ddtrace/compat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def _shadowed_dict(klass):
184184
pass
185185
else:
186186
if not (
187-
type(class_dict) is types.GetSetDescriptorType
187+
type(class_dict) is types.GetSetDescriptorType # noqa: E721
188188
and class_dict.__name__ == "__dict__" # noqa: E721,E261,W504
189189
and class_dict.__objclass__ is entry # noqa: E261,W504
190190
):

ddtrace/opentracer/tracer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def __init__(self, service_name=None, config=None, scope_manager=None, dd_tracer
6969
invalid_keys = config_invalid_keys(self._config)
7070
if invalid_keys:
7171
str_invalid_keys = ','.join(invalid_keys)
72-
raise ConfigException('invalid key(s) given (%s)'.format(str_invalid_keys))
72+
raise ConfigException('invalid key(s) given ({})'.format(str_invalid_keys))
7373

7474
if not self._service_name:
7575
raise ConfigException(""" Cannot detect the \'service_name\'.

ddtrace/span.py

Lines changed: 63 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@
66
from .vendor import six
77
from .compat import StringIO, stringify, iteritems, numeric_types, time_ns, is_integer
88
from .constants import (
9-
NUMERIC_TAGS, MANUAL_DROP_KEY, MANUAL_KEEP_KEY,
10-
VERSION_KEY, SERVICE_VERSION_KEY, SPAN_MEASURED_KEY,
9+
NUMERIC_TAGS,
10+
MANUAL_DROP_KEY,
11+
MANUAL_KEEP_KEY,
12+
VERSION_KEY,
13+
SERVICE_VERSION_KEY,
14+
SPAN_MEASURED_KEY,
1115
SERVICE_KEY,
1216
)
1317
from .ext import SpanTypes, errors, priority, net, http
@@ -27,33 +31,32 @@ class Span(object):
2731

2832
__slots__ = [
2933
# Public span attributes
30-
'service',
31-
'name',
32-
'resource',
33-
'span_id',
34-
'trace_id',
35-
'parent_id',
36-
'meta',
37-
'error',
38-
'metrics',
39-
'span_type',
40-
'start_ns',
41-
'duration_ns',
42-
'tracer',
34+
"service",
35+
"name",
36+
"resource",
37+
"span_id",
38+
"trace_id",
39+
"parent_id",
40+
"meta",
41+
"error",
42+
"metrics",
43+
"span_type",
44+
"start_ns",
45+
"duration_ns",
46+
"tracer",
4347
# Sampler attributes
44-
'sampled',
48+
"sampled",
4549
# Internal attributes
46-
'_context',
47-
'finished',
48-
'_parent',
49-
'__weakref__',
50+
"_context",
51+
"finished",
52+
"_parent",
53+
"__weakref__",
5054
]
5155

5256
def __init__(
5357
self,
5458
tracer,
5559
name,
56-
5760
service=None,
5861
resource=None,
5962
span_type=None,
@@ -150,14 +153,14 @@ def finish(self, finish_time=None):
150153
try:
151154
self._context.close_span(self)
152155
except Exception:
153-
log.exception('error recording finished trace')
156+
log.exception("error recording finished trace")
154157
else:
155158
# if a tracer is available to process the current context
156159
if self.tracer:
157160
try:
158161
self.tracer.record(self._context)
159162
except Exception:
160-
log.exception('error recording finished trace')
163+
log.exception("error recording finished trace")
161164

162165
def set_tag(self, key, value=None):
163166
"""Set a tag key/value pair on the span.
@@ -185,7 +188,7 @@ def set_tag(self, key, value=None):
185188

186189
# Explicitly try to convert expected integers to `int`
187190
# DEV: Some integrations parse these values from strings, but don't call `int(value)` themselves
188-
INT_TYPES = (net.TARGET_PORT, )
191+
INT_TYPES = (net.TARGET_PORT,)
189192
if key in INT_TYPES and not val_is_an_int:
190193
try:
191194
value = int(value)
@@ -272,7 +275,7 @@ def set_metric(self, key, value):
272275
try:
273276
value = int(bool(value))
274277
except (ValueError, TypeError):
275-
log.warning('failed to convert %r tag to an integer from %r', key, value)
278+
log.warning("failed to convert %r tag to an integer from %r", key, value)
276279
return
277280

278281
# FIXME[matt] we could push this check to serialization time as well.
@@ -283,12 +286,12 @@ def set_metric(self, key, value):
283286
try:
284287
value = float(value)
285288
except (ValueError, TypeError):
286-
log.debug('ignoring not number metric %s:%s', key, value)
289+
log.debug("ignoring not number metric %s:%s", key, value)
287290
return
288291

289292
# don't allow nan or inf
290293
if math.isnan(value) or math.isinf(value):
291-
log.debug('ignoring not real metric %s:%s', key, value)
294+
log.debug("ignoring not real metric %s:%s", key, value)
292295
return
293296

294297
if key in self.meta:
@@ -305,36 +308,36 @@ def get_metric(self, key):
305308

306309
def to_dict(self):
307310
d = {
308-
'trace_id': self.trace_id,
309-
'parent_id': self.parent_id,
310-
'span_id': self.span_id,
311-
'service': self.service,
312-
'resource': self.resource,
313-
'name': self.name,
314-
'error': self.error,
311+
"trace_id": self.trace_id,
312+
"parent_id": self.parent_id,
313+
"span_id": self.span_id,
314+
"service": self.service,
315+
"resource": self.resource,
316+
"name": self.name,
317+
"error": self.error,
315318
}
316319

317320
# a common mistake is to set the error field to a boolean instead of an
318321
# int. let's special case that here, because it's sure to happen in
319322
# customer code.
320-
err = d.get('error')
323+
err = d.get("error")
321324
if err and type(err) == bool:
322-
d['error'] = 1
325+
d["error"] = 1
323326

324327
if self.start_ns:
325-
d['start'] = self.start_ns
328+
d["start"] = self.start_ns
326329

327330
if self.duration_ns:
328-
d['duration'] = self.duration_ns
331+
d["duration"] = self.duration_ns
329332

330333
if self.meta:
331-
d['meta'] = self.meta
334+
d["meta"] = self.meta
332335

333336
if self.metrics:
334-
d['metrics'] = self.metrics
337+
d["metrics"] = self.metrics
335338

336339
if self.span_type:
337-
d['type'] = self.span_type
340+
d["type"] = self.span_type
338341

339342
return d
340343

@@ -344,10 +347,10 @@ def set_traceback(self, limit=20):
344347
"""
345348
(exc_type, exc_val, exc_tb) = sys.exc_info()
346349

347-
if (exc_type and exc_val and exc_tb):
350+
if exc_type and exc_val and exc_tb:
348351
self.set_exc_info(exc_type, exc_val, exc_tb)
349352
else:
350-
tb = ''.join(traceback.format_stack(limit=limit + 1)[:-1])
353+
tb = "".join(traceback.format_stack(limit=limit + 1)[:-1])
351354
self.set_tag(errors.ERROR_STACK, tb) # FIXME[gabin] Want to replace 'error.stack' tag with 'python.stack'
352355

353356
def set_exc_info(self, exc_type, exc_val, exc_tb):
@@ -363,7 +366,7 @@ def set_exc_info(self, exc_type, exc_val, exc_tb):
363366
tb = buff.getvalue()
364367

365368
# readable version of type (e.g. exceptions.ZeroDivisionError)
366-
exc_type_str = '%s.%s' % (exc_type.__module__, exc_type.__name__)
369+
exc_type_str = "%s.%s" % (exc_type.__module__, exc_type.__name__)
367370

368371
self.set_tag(errors.ERROR_MSG, exc_val)
369372
self.set_tag(errors.ERROR_TYPE, exc_type_str)
@@ -379,22 +382,22 @@ def _remove_exc_info(self):
379382
def pprint(self):
380383
""" Return a human readable version of the span. """
381384
lines = [
382-
('name', self.name),
383-
('id', self.span_id),
384-
('trace_id', self.trace_id),
385-
('parent_id', self.parent_id),
386-
('service', self.service),
387-
('resource', self.resource),
388-
('type', self.span_type),
389-
('start', self.start),
390-
('end', '' if not self.duration else self.start + self.duration),
391-
('duration', '%fs' % (self.duration or 0)),
392-
('error', self.error),
393-
('tags', '')
385+
("name", self.name),
386+
("id", self.span_id),
387+
("trace_id", self.trace_id),
388+
("parent_id", self.parent_id),
389+
("service", self.service),
390+
("resource", self.resource),
391+
("type", self.span_type),
392+
("start", self.start),
393+
("end", "" if not self.duration else self.start + self.duration),
394+
("duration", "%fs" % (self.duration or 0)),
395+
("error", self.error),
396+
("tags", ""),
394397
]
395398

396-
lines.extend((' ', '%s:%s' % kv) for kv in sorted(self.meta.items()))
397-
return '\n'.join('%10s %s' % l for l in lines)
399+
lines.extend((" ", "%s:%s" % kv) for kv in sorted(self.meta.items()))
400+
return "\n".join("%10s %s" % line for line in lines)
398401

399402
@property
400403
def context(self):
@@ -414,10 +417,10 @@ def __exit__(self, exc_type, exc_val, exc_tb):
414417
self.set_exc_info(exc_type, exc_val, exc_tb)
415418
self.finish()
416419
except Exception:
417-
log.exception('error closing trace')
420+
log.exception("error closing trace")
418421

419422
def __repr__(self):
420-
return '<Span(id=%s,trace_id=%s,parent_id=%s,name=%s)>' % (
423+
return "<Span(id=%s,trace_id=%s,parent_id=%s,name=%s)>" % (
421424
self.span_id,
422425
self.trace_id,
423426
self.parent_id,

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ exclude = '''
1919
| build/
2020
| dist/
2121
| ddtrace/(
22-
(?!compat\.py$)[^/]+\.py$
22+
(?!(compat|span|__init__)\.py$)[^/]+\.py$
2323
| commands/
2424
| contrib/
2525
(

tests/contrib/asyncio/test_tracer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ def test_trace_multiple_coroutines_ot_inner(self):
383383
# if multiple coroutines have nested tracing, they must belong
384384
# to the same trace
385385
ot_tracer = init_tracer('asyncio_svc', self.tracer)
386+
386387
@asyncio.coroutine
387388
def coro():
388389
# another traced coroutine

tests/profiling/exporter/test_http.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,4 +377,3 @@ def test_get_tags_override(monkeypatch):
377377
assert tags["profiler_version"] == ddtrace.__version__.encode("utf-8")
378378
assert tags["version"] == b"123"
379379
assert tags["env"] == b"prod"
380-

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ commands=black --check .
545545
commands_pre=
546546
skip_install=true
547547
deps=
548-
flake8>=3.7,<=3.8
548+
flake8>=3.8,<=3.9
549549
flake8-blind-except
550550
flake8-builtins
551551
flake8-docstrings

0 commit comments

Comments
 (0)