28
28
29
29
# stdlib
30
30
import builtins
31
+ from contextlib import suppress
31
32
from inspect import cleandoc
32
33
from types import MethodType
33
34
from typing import Any , Callable , Dict , Optional , Sequence , Type , TypeVar , Union
34
35
35
36
# this package
36
- from domdf_python_tools .compat import PYPY
37
+ from domdf_python_tools .compat import PYPY , PYPY37
37
38
from domdf_python_tools .typing import MethodDescriptorType , MethodWrapperType , WrapperDescriptorType
38
39
39
40
__all__ = [
@@ -335,6 +336,13 @@ def _do_prettify(obj: Type, base: Type, new_docstrings: Dict[str, str]):
335
336
continue
336
337
elif PYPY and isinstance (attribute , MethodType ):
337
338
continue # pragma: no cover (!PyPy)
339
+ elif PYPY37 :
340
+ if attribute is getattr (object , attr_name , None ):
341
+ continue
342
+ elif attribute is getattr (float , attr_name , None ):
343
+ continue
344
+ elif attribute is getattr (str , attr_name , None ):
345
+ continue
338
346
339
347
if attribute is None :
340
348
continue
@@ -345,7 +353,8 @@ def _do_prettify(obj: Type, base: Type, new_docstrings: Dict[str, str]):
345
353
346
354
doc : Optional [str ] = attribute .__doc__
347
355
if doc in {None , base_docstring }:
348
- attribute .__doc__ = new_docstrings [attr_name ]
356
+ with suppress (AttributeError , TypeError ):
357
+ attribute .__doc__ = new_docstrings [attr_name ]
349
358
350
359
351
360
def prettify_docstrings (obj : Type ) -> Type :
@@ -372,10 +381,8 @@ def prettify_docstrings(obj: Type) -> Type:
372
381
if "return" not in annotations or annotations ["return" ] is Any :
373
382
annotations ["return" ] = new_return_types [attribute ]
374
383
375
- try :
384
+ with suppress ( AttributeError , TypeError ) :
376
385
getattr (obj , attribute ).__annotations__ = annotations
377
- except AttributeError : # pragma: no cover
378
- pass
379
386
380
387
if issubclass (obj , tuple ) and obj .__repr__ .__doc__ == "Return a nicely formatted representation string" :
381
388
obj .__repr__ .__doc__ = repr_docstring
0 commit comments