Skip to content

Cleanup after drop of support for Python < 3.7 #387

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 0 additions & 26 deletions .travis.yml

This file was deleted.

11 changes: 3 additions & 8 deletions aws_xray_sdk/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
from .async_recorder import AsyncAWSXRayRecorder
from .patcher import patch, patch_all
from .recorder import AWSXRayRecorder
from .patcher import patch_all, patch
from .utils.compat import PY35


if not PY35:
xray_recorder = AWSXRayRecorder()
else:
from .async_recorder import AsyncAWSXRayRecorder
xray_recorder = AsyncAWSXRayRecorder()
xray_recorder = AsyncAWSXRayRecorder()

__all__ = [
'patch',
Expand Down
27 changes: 6 additions & 21 deletions aws_xray_sdk/core/async_context.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import asyncio
import sys
import copy

from .context import Context as _Context

_GTE_PY37 = sys.version_info.major == 3 and sys.version_info.minor >= 7


class AsyncContext(_Context):
"""
Expand All @@ -16,7 +13,7 @@ class AsyncContext(_Context):
Also overrides clear_trace_entities
"""
def __init__(self, *args, loop=None, use_task_factory=True, **kwargs):
super(AsyncContext, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

self._loop = loop
if loop is None:
Expand All @@ -35,7 +32,7 @@ def clear_trace_entities(self):
self._local.clear()


class TaskLocalStorage(object):
class TaskLocalStorage:
"""
Simple task local storage
"""
Expand All @@ -51,10 +48,7 @@ def __setattr__(self, name, value):

else:
# Set task local attributes
if _GTE_PY37:
task = asyncio.current_task(loop=self._loop)
else:
task = asyncio.Task.current_task(loop=self._loop)
task = asyncio.current_task(loop=self._loop)
if task is None:
return None

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

if _GTE_PY37:
task = asyncio.current_task(loop=self._loop)
else:
task = asyncio.Task.current_task(loop=self._loop)
task = asyncio.current_task(loop=self._loop)
if task is None:
return None

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

def clear(self):
# If were in a task, clear the context dictionary
if _GTE_PY37:
task = asyncio.current_task(loop=self._loop)
else:
task = asyncio.Task.current_task(loop=self._loop)
task = asyncio.current_task(loop=self._loop)
if task is not None and hasattr(task, 'context'):
task.context.clear()

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

# Share context with new task if possible
if _GTE_PY37:
current_task = asyncio.current_task(loop=loop)
else:
current_task = asyncio.Task.current_task(loop=loop)
current_task = asyncio.current_task(loop=loop)
if current_task is not None and hasattr(current_task, 'context'):
if current_task.context.get('entities'):
# NOTE: (enowell) Because the `AWSXRayRecorder`'s `Context` decides
Expand Down
2 changes: 1 addition & 1 deletion aws_xray_sdk/core/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
CXT_MISSING_STRATEGY_KEY = 'AWS_XRAY_CONTEXT_MISSING'


class Context(object):
class Context:
"""
The context storage class to store trace entities(segments/subsegments).
The default implementation uses threadlocal to store these entities.
Expand Down
2 changes: 1 addition & 1 deletion aws_xray_sdk/core/daemon_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
DEFAULT_ADDRESS = '127.0.0.1:2000'


class DaemonConfig(object):
class DaemonConfig:
"""The class that stores X-Ray daemon configuration about
the ip address and port for UDP and TCP port. It gets the address
string from ``AWS_TRACING_DAEMON_ADDRESS`` and then from recorder's
Expand Down
2 changes: 1 addition & 1 deletion aws_xray_sdk/core/emitters/udp_emitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
DEFAULT_DAEMON_ADDRESS = '127.0.0.1:2000'


class UDPEmitter(object):
class UDPEmitter:
"""
The default emitter the X-Ray recorder uses to send segments/subsegments
to the X-Ray daemon over UDP using a non-blocking socket. If there is an
Expand Down
2 changes: 1 addition & 1 deletion aws_xray_sdk/core/models/default_dynamic_naming.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from ..utils.search_pattern import wildcard_match


class DefaultDynamicNaming(object):
class DefaultDynamicNaming:
"""
Decides what name to use on a segment generated from an incoming request.
By default it takes the host name and compares it to a pre-defined pattern.
Expand Down
6 changes: 3 additions & 3 deletions aws_xray_sdk/core/models/dummy_entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ class DummySegment(Segment):
def __init__(self, name='dummy'):
no_op_id = os.getenv('AWS_XRAY_NOOP_ID')
if no_op_id and no_op_id.lower() == 'false':
super(DummySegment, self).__init__(name=name, traceid=TraceId().to_id())
super().__init__(name=name, traceid=TraceId().to_id())
else:
super(DummySegment, self).__init__(name=name, traceid=NoOpTraceId().to_id(), entityid='0000000000000000')
super().__init__(name=name, traceid=NoOpTraceId().to_id(), entityid='0000000000000000')
self.sampled = False

def set_aws(self, aws_meta):
Expand Down Expand Up @@ -87,7 +87,7 @@ class DummySubsegment(Subsegment):
"""

def __init__(self, segment, name='dummy'):
super(DummySubsegment, self).__init__(name, 'dummy', segment)
super().__init__(name, 'dummy', segment)
no_op_id = os.getenv('AWS_XRAY_NOOP_ID')
if no_op_id and no_op_id.lower() == 'false':
super(Subsegment, self).__init__(name)
Expand Down
12 changes: 6 additions & 6 deletions aws_xray_sdk/core/models/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import json

from ..utils.compat import annotation_value_types, string_types
from ..utils.compat import annotation_value_types
from ..utils.conversion import metadata_to_dict
from .throwable import Throwable
from . import http
Expand All @@ -21,7 +21,7 @@
ORIGIN_TRACE_HEADER_ATTR_KEY = '_origin_trace_header'


class Entity(object):
class Entity:
"""
The parent class for segment/subsegment. It holds common properties
and methods on segment and subsegment.
Expand Down Expand Up @@ -113,7 +113,7 @@ def put_http_meta(self, key, value):
return

if key == http.STATUS:
if isinstance(value, string_types):
if isinstance(value, str):
value = int(value)
self.apply_status_code(value)

Expand All @@ -139,7 +139,7 @@ def put_annotation(self, key, value):
"""
self._check_ended()

if not isinstance(key, string_types):
if not isinstance(key, str):
log.warning("ignoring non string type annotation key with type %s.", type(key))
return

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

if not isinstance(namespace, string_types):
if not isinstance(namespace, str):
log.warning("ignoring non string type metadata namespace")
return

Expand Down Expand Up @@ -271,7 +271,7 @@ def serialize(self):
def to_dict(self):
"""
Convert Entity(Segment/Subsegment) object to dict
with required properties that have non-empty values.
with required properties that have non-empty values.
"""
entity_dict = {}

Expand Down
2 changes: 1 addition & 1 deletion aws_xray_sdk/core/models/facade_segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(self, name, entityid, traceid, sampled):
sampled=sampled,
)

super(FacadeSegment, self).__init__(
super().__init__(
name=name,
entityid=entityid,
traceid=traceid,
Expand Down
10 changes: 5 additions & 5 deletions aws_xray_sdk/core/models/segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def __init__(self, name, entityid=None, traceid=None,
if not name:
raise SegmentNameMissingException("Segment name is required.")

super(Segment, self).__init__(name)
super().__init__(name)

if not traceid:
traceid = TraceId().to_id()
Expand All @@ -85,7 +85,7 @@ def add_subsegment(self, subsegment):
Add input subsegment as a child subsegment and increment
reference counter and total subsegments counter.
"""
super(Segment, self).add_subsegment(subsegment)
super().add_subsegment(subsegment)
self.increment()

def increment(self):
Expand Down Expand Up @@ -127,15 +127,15 @@ def remove_subsegment(self, subsegment):
"""
Remove the reference of input subsegment.
"""
super(Segment, self).remove_subsegment(subsegment)
super().remove_subsegment(subsegment)
self.decrement_subsegments_size()

def set_user(self, user):
"""
set user of a segment. One segment can only have one user.
User is indexed and can be later queried.
"""
super(Segment, self)._check_ended()
super()._check_ended()
self.user = user

def set_service(self, service_info):
Expand All @@ -160,7 +160,7 @@ def to_dict(self):
Convert Segment object to dict with required properties
that have non-empty values.
"""
segment_dict = super(Segment, self).to_dict()
segment_dict = super().to_dict()

del segment_dict['ref_counter']
del segment_dict['_subsegments_counter']
Expand Down
10 changes: 5 additions & 5 deletions aws_xray_sdk/core/models/subsegment.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def __init__(self, name, namespace, segment):
support `aws`, `remote` and `local`.
:param Segment segment: The parent segment
"""
super(Subsegment, self).__init__(name)
super().__init__(name)

if not segment:
raise SegmentNotFoundException("A parent segment is required for creating subsegments.")
Expand All @@ -114,7 +114,7 @@ def add_subsegment(self, subsegment):
reference counter and total subsegments counter of the
parent segment.
"""
super(Subsegment, self).add_subsegment(subsegment)
super().add_subsegment(subsegment)
self.parent_segment.increment()

def remove_subsegment(self, subsegment):
Expand All @@ -124,7 +124,7 @@ def remove_subsegment(self, subsegment):

:param Subsegment: subsegment to remove.
"""
super(Subsegment, self).remove_subsegment(subsegment)
super().remove_subsegment(subsegment)
self.parent_segment.decrement_subsegments_size()

def close(self, end_time=None):
Expand All @@ -136,7 +136,7 @@ def close(self, end_time=None):
:param int end_time: Epoch in seconds. If not specified
current time will be used.
"""
super(Subsegment, self).close(end_time)
super().close(end_time)
self.parent_segment.decrement_ref_counter()

def set_sql(self, sql):
Expand All @@ -154,7 +154,7 @@ def to_dict(self):
Convert Subsegment object to dict with required properties
that have non-empty values.
"""
subsegment_dict = super(Subsegment, self).to_dict()
subsegment_dict = super().to_dict()

del subsegment_dict['parent_segment']

Expand Down
6 changes: 2 additions & 4 deletions aws_xray_sdk/core/models/throwable.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
import binascii
import logging

from ..utils.compat import string_types

log = logging.getLogger(__name__)


class Throwable(object):
class Throwable:
"""
An object recording exception infomation under trace entity
`cause` section. The information includes the stack trace,
Expand All @@ -31,7 +29,7 @@ def __init__(self, exception, stack, remote=False):
message = None

# do not record non-string exception message
if isinstance(message, string_types):
if isinstance(message, str):
self.message = message

self.type = type(exception).__name__
Expand Down
2 changes: 1 addition & 1 deletion aws_xray_sdk/core/models/trace_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
HEADER_DELIMITER = ";"


class TraceHeader(object):
class TraceHeader:
"""
The sampling decision and trace ID are added to HTTP requests in
tracing headers named ``X-Amzn-Trace-Id``. The first X-Ray-integrated
Expand Down
21 changes: 9 additions & 12 deletions aws_xray_sdk/core/patcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import wrapt

from aws_xray_sdk import global_sdk_config
from .utils.compat import PY2, is_classmethod, is_instance_method
from .utils.compat import is_classmethod, is_instance_method

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -55,17 +55,14 @@ def patch_all(double_patch=False):

def _is_valid_import(module):
module = module.replace('.', '/')
if PY2:
return bool(pkgutil.get_loader(module))
else:
realpath = os.path.realpath(module)
is_module = os.path.isdir(realpath) and (
os.path.isfile('{}/__init__.py'.format(module)) or os.path.isfile('{}/__init__.pyc'.format(module))
)
is_file = not is_module and (
os.path.isfile('{}.py'.format(module)) or os.path.isfile('{}.pyc'.format(module))
)
return is_module or is_file
realpath = os.path.realpath(module)
is_module = os.path.isdir(realpath) and (
os.path.isfile('{}/__init__.py'.format(module)) or os.path.isfile('{}/__init__.pyc'.format(module))
)
is_file = not is_module and (
os.path.isfile('{}.py'.format(module)) or os.path.isfile('{}.pyc'.format(module))
)
return is_module or is_file


def patch(modules_to_patch, raise_errors=True, ignore_module_patterns=None):
Expand Down
Loading