@@ -147,104 +147,6 @@ def make_async_decorator(tracer, fn, *params, **kw_params):
147147 return fn
148148
149149
150- # static version of getattr backported from Python 3.7
151- try :
152- from inspect import getattr_static
153- except ImportError :
154- import types
155-
156- _sentinel = object ()
157-
158- def _static_getmro (klass ):
159- return type .__dict__ ["__mro__" ].__get__ (klass )
160-
161- def _check_instance (obj , attr ):
162- instance_dict = {}
163- try :
164- instance_dict = object .__getattribute__ (obj , "__dict__" )
165- except AttributeError :
166- pass
167- return dict .get (instance_dict , attr , _sentinel )
168-
169- def _check_class (klass , attr ):
170- for entry in _static_getmro (klass ):
171- if _shadowed_dict (type (entry )) is _sentinel :
172- try :
173- return entry .__dict__ [attr ]
174- except KeyError :
175- pass
176- return _sentinel
177-
178- def _is_type (obj ):
179- try :
180- _static_getmro (obj )
181- except TypeError :
182- return False
183- return True
184-
185- def _shadowed_dict (klass ):
186- dict_attr = type .__dict__ ["__dict__" ]
187- for entry in _static_getmro (klass ):
188- try :
189- class_dict = dict_attr .__get__ (entry )["__dict__" ]
190- except KeyError :
191- pass
192- else :
193- if not (
194- type (class_dict ) is types .GetSetDescriptorType # noqa: E721
195- and class_dict .__name__ == "__dict__" # noqa: E721,E261,W504
196- and class_dict .__objclass__ is entry # noqa: E261,W504
197- ):
198- return class_dict
199- return _sentinel
200-
201- def getattr_static (obj , attr , default = _sentinel ):
202- """Retrieve attributes without triggering dynamic lookup via the
203- descriptor protocol, __getattr__ or __getattribute__.
204-
205- Note: this function may not be able to retrieve all attributes
206- that getattr can fetch (like dynamically created attributes)
207- and may find attributes that getattr can't (like descriptors
208- that raise AttributeError). It can also return descriptor objects
209- instead of instance members in some cases. See the
210- documentation for details.
211- """
212- instance_result = _sentinel
213- if not _is_type (obj ):
214- klass = type (obj )
215- dict_attr = _shadowed_dict (klass )
216- if dict_attr is _sentinel or type (dict_attr ) is types .MemberDescriptorType : # noqa: E261,E721,W504
217- instance_result = _check_instance (obj , attr )
218- else :
219- klass = obj
220-
221- klass_result = _check_class (klass , attr )
222-
223- if instance_result is not _sentinel and klass_result is not _sentinel :
224- if (
225- _check_class (type (klass_result ), "__get__" ) is not _sentinel
226- and _check_class (type (klass_result ), "__set__" ) is not _sentinel # noqa: W504,E261,E721
227- ):
228- return klass_result
229-
230- if instance_result is not _sentinel :
231- return instance_result
232- if klass_result is not _sentinel :
233- return klass_result
234-
235- if obj is klass :
236- # for types we check the metaclass too
237- for entry in _static_getmro (type (klass )):
238- if _shadowed_dict (type (entry )) is _sentinel :
239- try :
240- return entry .__dict__ [attr ]
241- except KeyError :
242- pass
243- if default is not _sentinel :
244- return default
245- raise AttributeError (attr )
246-
247-
248150# DEV: There is `six.u()` which does something similar, but doesn't have the guard around `hasattr(s, 'decode')`
249151def to_unicode (s ):
250152 """ Return a unicode string for the given bytes or string instance. """
0 commit comments