Skip to content

Commit 7fadfee

Browse files
committed
Fixing _do_prettify for PyPy
1 parent f4ff164 commit 7fadfee

File tree

4 files changed

+74
-61
lines changed

4 files changed

+74
-61
lines changed

domdf_python_tools/doctools.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
# stdlib
3030
import builtins
31+
import platform
3132
from textwrap import dedent
3233
from typing import Any, Callable, Dict, Optional, Sequence, Type, TypeVar, Union
3334

@@ -47,6 +48,7 @@
4748
]
4849

4950
F = TypeVar('F', bound=Callable[..., Any])
51+
PYPY = platform.python_implementation() == "PyPy"
5052

5153

5254
def deindent_string(string: Optional[str]) -> str:
@@ -311,15 +313,22 @@ def _do_prettify(obj: Type, base: Type, new_docstrings: Dict[str, str]):
311313

312314
for attr_name in new_docstrings:
313315

314-
if hasattr(obj, attr_name):
315-
attribute = getattr(obj, attr_name)
316+
if not hasattr(obj, attr_name):
317+
continue
316318

317-
if not isinstance(attribute, (WrapperDescriptorType, MethodDescriptorType, MethodWrapperType)):
319+
attribute = getattr(obj, attr_name)
318320

319-
doc: Optional[str] = getattr(obj, attr_name).__doc__
321+
if not PYPY and isinstance(attribute, (WrapperDescriptorType, MethodDescriptorType, MethodWrapperType)):
322+
continue
320323

321-
if doc in {None, getattr(base, attr_name).__doc__}:
322-
getattr(obj, attr_name).__doc__ = new_docstrings[attr_name]
324+
base_docstring: Optional[str] = None
325+
if hasattr(base, attr_name):
326+
base_docstring = getattr(base, attr_name).__doc__
327+
328+
doc: Optional[str] = getattr(obj, attr_name).__doc__
329+
330+
if doc in {None, base_docstring}:
331+
getattr(obj, attr_name).__doc__ = new_docstrings[attr_name]
323332

324333

325334
def prettify_docstrings(obj: Type) -> Type:

domdf_python_tools/typing.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,14 @@
4343
import pathlib
4444
from decimal import Decimal
4545
from json import JSONDecoder, JSONEncoder
46-
from typing import Any, Callable, Dict, List, Optional, Tuple, Type, Union, runtime_checkable
46+
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Tuple, Type, Union
4747

4848
# 3rd party
49-
from typing_extensions import Protocol
49+
from typing_extensions import Protocol, runtime_checkable
50+
51+
if TYPE_CHECKING:
52+
# 3rd party
53+
from pandas._typing import FrameOrSeries # type: ignore
5054

5155
__all__ = [
5256
"PathLike",

domdf_python_tools/utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
if TYPE_CHECKING:
6868
# 3rd party
6969
from pandas import DataFrame, Series # type: ignore
70-
from pandas._typing import FrameOrSeries # type: ignore
7170

7271
__all__ = [
7372
"pyversion",

tests/test_doctools.py

Lines changed: 53 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515

1616
# this package
1717
from domdf_python_tools import doctools
18-
# TODO: test sphinxification of docstrings
1918
from domdf_python_tools.doctools import (
2019
base_int_docstrings, base_new_docstrings, container_docstrings, operator_docstrings, prettify_docstrings
2120
)
2221

22+
# TODO: test sphinxification of docstrings
23+
2324

2425
class Cafe:
2526
"""
@@ -347,157 +348,157 @@ def demo_function():
347348
@prettify_docstrings
348349
class Klasse:
349350

350-
def __delattr__(self, **kwargs):
351+
def __delattr__(self, **kwargs): # type: ignore
351352
... # pragma: no cover
352353

353-
def __dir__(self):
354+
def __dir__(self): # type: ignore
354355
... # pragma: no cover
355356

356-
def __eq__(self, **kwargs):
357+
def __eq__(self, **kwargs): # type: ignore
357358
... # pragma: no cover
358359

359-
def __getattribute__(self, **kwargs):
360+
def __getattribute__(self, **kwargs): # type: ignore
360361
... # pragma: no cover
361362

362-
def __ge__(self):
363+
def __ge__(self): # type: ignore
363364
... # pragma: no cover
364365

365-
def __gt__(self):
366+
def __gt__(self): # type: ignore
366367
... # pragma: no cover
367368

368-
def __hash__(self):
369+
def __hash__(self): # type: ignore
369370
... # pragma: no cover
370371

371-
def __lt__(self):
372+
def __lt__(self): # type: ignore
372373
... # pragma: no cover
373374

374-
def __le__(self):
375+
def __le__(self): # type: ignore
375376
... # pragma: no cover
376377

377-
def __ne__(self, **kwargs):
378+
def __ne__(self, **kwargs): # type: ignore
378379
... # pragma: no cover
379380

380-
def __setattr__(self, **kwargs):
381+
def __setattr__(self, **kwargs): # type: ignore
381382
... # pragma: no cover
382383

383-
def __sizeof__(self):
384+
def __sizeof__(self): # type: ignore
384385
... # pragma: no cover
385386

386-
def __str__(self):
387+
def __str__(self): # type: ignore
387388
... # pragma: no cover
388389

389-
def __contains__(self):
390+
def __contains__(self): # type: ignore
390391
... # pragma: no cover
391392

392-
def __getitem__(self):
393+
def __getitem__(self): # type: ignore
393394
... # pragma: no cover
394395

395-
def __setitem__(self):
396+
def __setitem__(self): # type: ignore
396397
... # pragma: no cover
397398

398-
def __delitem__(self):
399+
def __delitem__(self): # type: ignore
399400
... # pragma: no cover
400401

401-
def __and__(self):
402+
def __and__(self): # type: ignore
402403
... # pragma: no cover
403404

404-
def __add__(self):
405+
def __add__(self): # type: ignore
405406
... # pragma: no cover
406407

407-
def __abs__(self):
408+
def __abs__(self): # type: ignore
408409
... # pragma: no cover
409410

410-
def __divmod__(self):
411+
def __divmod__(self): # type: ignore
411412
... # pragma: no cover
412413

413-
def __floordiv__(self):
414+
def __floordiv__(self): # type: ignore
414415
... # pragma: no cover
415416

416-
def __invert__(self):
417+
def __invert__(self): # type: ignore
417418
... # pragma: no cover
418419

419-
def __lshift__(self):
420+
def __lshift__(self): # type: ignore
420421
... # pragma: no cover
421422

422-
def __mod__(self):
423+
def __mod__(self): # type: ignore
423424
... # pragma: no cover
424425

425-
def __mul__(self):
426+
def __mul__(self): # type: ignore
426427
... # pragma: no cover
427428

428-
def __neg__(self):
429+
def __neg__(self): # type: ignore
429430
... # pragma: no cover
430431

431-
def __or__(self):
432+
def __or__(self): # type: ignore
432433
... # pragma: no cover
433434

434-
def __pos__(self):
435+
def __pos__(self): # type: ignore
435436
... # pragma: no cover
436437

437-
def __pow__(self):
438+
def __pow__(self): # type: ignore
438439
... # pragma: no cover
439440

440-
def __radd__(self):
441+
def __radd__(self): # type: ignore
441442
... # pragma: no cover
442443

443-
def __rand__(self):
444+
def __rand__(self): # type: ignore
444445
... # pragma: no cover
445446

446-
def __rdivmod__(self):
447+
def __rdivmod__(self): # type: ignore
447448
... # pragma: no cover
448449

449-
def __rfloordiv__(self):
450+
def __rfloordiv__(self): # type: ignore
450451
... # pragma: no cover
451452

452-
def __rlshift__(self):
453+
def __rlshift__(self): # type: ignore
453454
... # pragma: no cover
454455

455-
def __rmod__(self):
456+
def __rmod__(self): # type: ignore
456457
... # pragma: no cover
457458

458-
def __rmul__(self):
459+
def __rmul__(self): # type: ignore
459460
... # pragma: no cover
460461

461-
def __ror__(self):
462+
def __ror__(self): # type: ignore
462463
... # pragma: no cover
463464

464-
def __rpow__(self):
465+
def __rpow__(self): # type: ignore
465466
... # pragma: no cover
466467

467-
def __rrshift__(self):
468+
def __rrshift__(self): # type: ignore
468469
... # pragma: no cover
469470

470-
def __rshift__(self):
471+
def __rshift__(self): # type: ignore
471472
... # pragma: no cover
472473

473-
def __rsub__(self):
474+
def __rsub__(self): # type: ignore
474475
... # pragma: no cover
475476

476-
def __rtruediv__(self):
477+
def __rtruediv__(self): # type: ignore
477478
... # pragma: no cover
478479

479-
def __rxor__(self):
480+
def __rxor__(self): # type: ignore
480481
... # pragma: no cover
481482

482-
def __sub__(self):
483+
def __sub__(self): # type: ignore
483484
... # pragma: no cover
484485

485-
def __truediv__(self):
486+
def __truediv__(self): # type: ignore
486487
... # pragma: no cover
487488

488-
def __xor__(self):
489+
def __xor__(self): # type: ignore
489490
... # pragma: no cover
490491

491-
def __float__(self):
492+
def __float__(self): # type: ignore
492493
... # pragma: no cover
493494

494-
def __int__(self):
495+
def __int__(self): # type: ignore
495496
... # pragma: no cover
496497

497-
def __repr__(self):
498+
def __repr__(self): # type: ignore
498499
... # pragma: no cover
499500

500-
def __bool__(self):
501+
def __bool__(self): # type: ignore
501502
... # pragma: no cover
502503

503504

0 commit comments

Comments
 (0)