@@ -61,7 +61,7 @@ def my_factory_for_t(api_type: typing.Type[T]) -> typing.Optional[T]:
61
61
means that the Python interpreter was invoked with the ``-E`` or ``-I`` flag).
62
62
"""
63
63
64
- from typing import Type , TypeVar , Optional , Callable
64
+ from typing import Callable , Optional , Type , TypeVar
65
65
import importlib
66
66
import os
67
67
import sys
@@ -78,10 +78,11 @@ def my_factory_for_t(api_type: typing.Type[T]) -> typing.Optional[T]:
78
78
# annotate setters, were it not for https://github.com/python/mypy/issues/7092
79
79
# Once that bug is resolved, setters should use this instead of duplicating the
80
80
# code.
81
- #ImplementationFactory = Callable[[Type[_T]], Optional[_T]]
81
+ # ImplementationFactory = Callable[[Type[_T]], Optional[_T]]
82
82
83
83
_DEFAULT_FACTORY : Optional [_UntrustedImplFactory [object ]] = None
84
84
85
+
85
86
def _try_load_impl_from_modname (
86
87
implementation_modname : str , api_type : Type [_T ]) -> Optional [_T ]:
87
88
try :
@@ -92,6 +93,7 @@ def _try_load_impl_from_modname(
92
93
93
94
return _try_load_impl_from_mod (implementation_mod , api_type )
94
95
96
+
95
97
def _try_load_impl_from_mod (
96
98
implementation_mod : object , api_type : Type [_T ]) -> Optional [_T ]:
97
99
@@ -109,6 +111,7 @@ def _try_load_impl_from_mod(
109
111
110
112
return _try_load_impl_from_callback (implementation_fn , api_type )
111
113
114
+
112
115
def _try_load_impl_from_callback (
113
116
implementation_fn : _UntrustedImplFactory [_T ],
114
117
api_type : Type [_T ]
@@ -149,11 +152,10 @@ def _try_load_configured_impl(
149
152
return _try_load_impl_from_callback (_DEFAULT_FACTORY , api_type )
150
153
return None
151
154
155
+
152
156
# Public to other opentelemetry-api modules
153
- def _load_impl (
154
- api_type : Type [_T ],
155
- factory : Optional [Callable [[Type [_T ]], Optional [_T ]]]
156
- ) -> _T :
157
+ def _load_impl (api_type : Type [_T ],
158
+ factory : Optional [Callable [[Type [_T ]], Optional [_T ]]]) -> _T :
157
159
"""Tries to load a configured implementation, if unsuccessful, returns a
158
160
fast no-op implemenation that is always available.
159
161
"""
@@ -163,9 +165,10 @@ def _load_impl(
163
165
return api_type ()
164
166
return result
165
167
168
+
166
169
def set_preferred_default_implementation (
167
170
implementation_factory : _UntrustedImplFactory [_T ]) -> None :
168
171
"""Sets a factory function that may be called for any implementation
169
172
object. See the :ref:`module docs <loader-factory>` for more details."""
170
- global _DEFAULT_FACTORY # pylint:disable=global-statement
173
+ global _DEFAULT_FACTORY # pylint:disable=global-statement
171
174
_DEFAULT_FACTORY = implementation_factory
0 commit comments