11import asyncio
2- import sys
32import copy
43
54from .context import Context as _Context
65
7- _GTE_PY37 = sys .version_info .major == 3 and sys .version_info .minor >= 7
8-
96
107class 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
0 commit comments