Skip to content

Commit 150f0ea

Browse files
authored
Cleanup after drop of support for Python < 3.7 (#387)
* Remove unused config for Travis CI * Remove classifiers for unsupported Python versions * Add `python_requires` and remove unused dependencies * Use Python 3 style `super()` calls * Use “new style” classes Stop inheriting from object explicitly * Remove compatibility code for Python < 3.7 * Remove unnecessary future imports * Remove `string_types` from compat module
1 parent c57d293 commit 150f0ea

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+123
-267
lines changed

.travis.yml

Lines changed: 0 additions & 26 deletions
This file was deleted.

aws_xray_sdk/core/__init__.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1+
from .async_recorder import AsyncAWSXRayRecorder
2+
from .patcher import patch, patch_all
13
from .recorder import AWSXRayRecorder
2-
from .patcher import patch_all, patch
3-
from .utils.compat import PY35
44

5-
6-
if not PY35:
7-
xray_recorder = AWSXRayRecorder()
8-
else:
9-
from .async_recorder import AsyncAWSXRayRecorder
10-
xray_recorder = AsyncAWSXRayRecorder()
5+
xray_recorder = AsyncAWSXRayRecorder()
116

127
__all__ = [
138
'patch',

aws_xray_sdk/core/async_context.py

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import asyncio
2-
import sys
32
import copy
43

54
from .context import Context as _Context
65

7-
_GTE_PY37 = sys.version_info.major == 3 and sys.version_info.minor >= 7
8-
96

107
class AsyncContext(_Context):
118
"""
@@ -16,7 +13,7 @@ class AsyncContext(_Context):
1613
Also overrides clear_trace_entities
1714
"""
1815
def __init__(self, *args, loop=None, use_task_factory=True, **kwargs):
19-
super(AsyncContext, self).__init__(*args, **kwargs)
16+
super().__init__(*args, **kwargs)
2017

2118
self._loop = loop
2219
if loop is None:
@@ -35,7 +32,7 @@ def clear_trace_entities(self):
3532
self._local.clear()
3633

3734

38-
class TaskLocalStorage(object):
35+
class TaskLocalStorage:
3936
"""
4037
Simple task local storage
4138
"""
@@ -51,10 +48,7 @@ def __setattr__(self, name, value):
5148

5249
else:
5350
# Set task local attributes
54-
if _GTE_PY37:
55-
task = asyncio.current_task(loop=self._loop)
56-
else:
57-
task = asyncio.Task.current_task(loop=self._loop)
51+
task = asyncio.current_task(loop=self._loop)
5852
if task is None:
5953
return None
6054

@@ -68,10 +62,7 @@ def __getattribute__(self, item):
6862
# Return references to local objects
6963
return object.__getattribute__(self, item)
7064

71-
if _GTE_PY37:
72-
task = asyncio.current_task(loop=self._loop)
73-
else:
74-
task = asyncio.Task.current_task(loop=self._loop)
65+
task = asyncio.current_task(loop=self._loop)
7566
if task is None:
7667
return None
7768

@@ -82,10 +73,7 @@ def __getattribute__(self, item):
8273

8374
def clear(self):
8475
# If were in a task, clear the context dictionary
85-
if _GTE_PY37:
86-
task = asyncio.current_task(loop=self._loop)
87-
else:
88-
task = asyncio.Task.current_task(loop=self._loop)
76+
task = asyncio.current_task(loop=self._loop)
8977
if task is not None and hasattr(task, 'context'):
9078
task.context.clear()
9179

@@ -104,10 +92,7 @@ def task_factory(loop, coro):
10492
del task._source_traceback[-1] # flake8: noqa
10593

10694
# Share context with new task if possible
107-
if _GTE_PY37:
108-
current_task = asyncio.current_task(loop=loop)
109-
else:
110-
current_task = asyncio.Task.current_task(loop=loop)
95+
current_task = asyncio.current_task(loop=loop)
11196
if current_task is not None and hasattr(current_task, 'context'):
11297
if current_task.context.get('entities'):
11398
# NOTE: (enowell) Because the `AWSXRayRecorder`'s `Context` decides

aws_xray_sdk/core/context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
CXT_MISSING_STRATEGY_KEY = 'AWS_XRAY_CONTEXT_MISSING'
1515

1616

17-
class Context(object):
17+
class Context:
1818
"""
1919
The context storage class to store trace entities(segments/subsegments).
2020
The default implementation uses threadlocal to store these entities.

aws_xray_sdk/core/daemon_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
DEFAULT_ADDRESS = '127.0.0.1:2000'
77

88

9-
class DaemonConfig(object):
9+
class DaemonConfig:
1010
"""The class that stores X-Ray daemon configuration about
1111
the ip address and port for UDP and TCP port. It gets the address
1212
string from ``AWS_TRACING_DAEMON_ADDRESS`` and then from recorder's

aws_xray_sdk/core/emitters/udp_emitter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
DEFAULT_DAEMON_ADDRESS = '127.0.0.1:2000'
1313

1414

15-
class UDPEmitter(object):
15+
class UDPEmitter:
1616
"""
1717
The default emitter the X-Ray recorder uses to send segments/subsegments
1818
to the X-Ray daemon over UDP using a non-blocking socket. If there is an

aws_xray_sdk/core/models/default_dynamic_naming.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from ..utils.search_pattern import wildcard_match
22

33

4-
class DefaultDynamicNaming(object):
4+
class DefaultDynamicNaming:
55
"""
66
Decides what name to use on a segment generated from an incoming request.
77
By default it takes the host name and compares it to a pre-defined pattern.

aws_xray_sdk/core/models/dummy_entities.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ class DummySegment(Segment):
1818
def __init__(self, name='dummy'):
1919
no_op_id = os.getenv('AWS_XRAY_NOOP_ID')
2020
if no_op_id and no_op_id.lower() == 'false':
21-
super(DummySegment, self).__init__(name=name, traceid=TraceId().to_id())
21+
super().__init__(name=name, traceid=TraceId().to_id())
2222
else:
23-
super(DummySegment, self).__init__(name=name, traceid=NoOpTraceId().to_id(), entityid='0000000000000000')
23+
super().__init__(name=name, traceid=NoOpTraceId().to_id(), entityid='0000000000000000')
2424
self.sampled = False
2525

2626
def set_aws(self, aws_meta):
@@ -87,7 +87,7 @@ class DummySubsegment(Subsegment):
8787
"""
8888

8989
def __init__(self, segment, name='dummy'):
90-
super(DummySubsegment, self).__init__(name, 'dummy', segment)
90+
super().__init__(name, 'dummy', segment)
9191
no_op_id = os.getenv('AWS_XRAY_NOOP_ID')
9292
if no_op_id and no_op_id.lower() == 'false':
9393
super(Subsegment, self).__init__(name)

aws_xray_sdk/core/models/entity.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import json
88

9-
from ..utils.compat import annotation_value_types, string_types
9+
from ..utils.compat import annotation_value_types
1010
from ..utils.conversion import metadata_to_dict
1111
from .throwable import Throwable
1212
from . import http
@@ -21,7 +21,7 @@
2121
ORIGIN_TRACE_HEADER_ATTR_KEY = '_origin_trace_header'
2222

2323

24-
class Entity(object):
24+
class Entity:
2525
"""
2626
The parent class for segment/subsegment. It holds common properties
2727
and methods on segment and subsegment.
@@ -113,7 +113,7 @@ def put_http_meta(self, key, value):
113113
return
114114

115115
if key == http.STATUS:
116-
if isinstance(value, string_types):
116+
if isinstance(value, str):
117117
value = int(value)
118118
self.apply_status_code(value)
119119

@@ -139,7 +139,7 @@ def put_annotation(self, key, value):
139139
"""
140140
self._check_ended()
141141

142-
if not isinstance(key, string_types):
142+
if not isinstance(key, str):
143143
log.warning("ignoring non string type annotation key with type %s.", type(key))
144144
return
145145

@@ -165,7 +165,7 @@ def put_metadata(self, key, value, namespace='default'):
165165
"""
166166
self._check_ended()
167167

168-
if not isinstance(namespace, string_types):
168+
if not isinstance(namespace, str):
169169
log.warning("ignoring non string type metadata namespace")
170170
return
171171

@@ -271,7 +271,7 @@ def serialize(self):
271271
def to_dict(self):
272272
"""
273273
Convert Entity(Segment/Subsegment) object to dict
274-
with required properties that have non-empty values.
274+
with required properties that have non-empty values.
275275
"""
276276
entity_dict = {}
277277

aws_xray_sdk/core/models/facade_segment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def __init__(self, name, entityid, traceid, sampled):
2222
sampled=sampled,
2323
)
2424

25-
super(FacadeSegment, self).__init__(
25+
super().__init__(
2626
name=name,
2727
entityid=entityid,
2828
traceid=traceid,

0 commit comments

Comments
 (0)