1
1
import asyncio
2
- import sys
3
2
import copy
4
3
5
4
from .context import Context as _Context
6
5
7
- _GTE_PY37 = sys .version_info .major == 3 and sys .version_info .minor >= 7
8
-
9
6
10
7
class AsyncContext (_Context ):
11
8
"""
@@ -16,7 +13,7 @@ class AsyncContext(_Context):
16
13
Also overrides clear_trace_entities
17
14
"""
18
15
def __init__ (self , * args , loop = None , use_task_factory = True , ** kwargs ):
19
- super (AsyncContext , self ).__init__ (* args , ** kwargs )
16
+ super ().__init__ (* args , ** kwargs )
20
17
21
18
self ._loop = loop
22
19
if loop is None :
@@ -35,7 +32,7 @@ def clear_trace_entities(self):
35
32
self ._local .clear ()
36
33
37
34
38
- class TaskLocalStorage ( object ) :
35
+ class TaskLocalStorage :
39
36
"""
40
37
Simple task local storage
41
38
"""
@@ -51,10 +48,7 @@ def __setattr__(self, name, value):
51
48
52
49
else :
53
50
# 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 )
58
52
if task is None :
59
53
return None
60
54
@@ -68,10 +62,7 @@ def __getattribute__(self, item):
68
62
# Return references to local objects
69
63
return object .__getattribute__ (self , item )
70
64
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 )
75
66
if task is None :
76
67
return None
77
68
@@ -82,10 +73,7 @@ def __getattribute__(self, item):
82
73
83
74
def clear (self ):
84
75
# 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 )
89
77
if task is not None and hasattr (task , 'context' ):
90
78
task .context .clear ()
91
79
@@ -104,10 +92,7 @@ def task_factory(loop, coro):
104
92
del task ._source_traceback [- 1 ] # flake8: noqa
105
93
106
94
# 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 )
111
96
if current_task is not None and hasattr (current_task , 'context' ):
112
97
if current_task .context .get ('entities' ):
113
98
# NOTE: (enowell) Because the `AWSXRayRecorder`'s `Context` decides
0 commit comments