7
7
from functools import cmp_to_key
8
8
from io import StringIO
9
9
from textwrap import dedent , indent
10
- from types import ModuleType
10
+ from types import FunctionType , ModuleType
11
11
from typing import (
12
12
IO ,
13
13
Any ,
@@ -54,7 +54,7 @@ def get_type(self) -> type:
54
54
return type (self )
55
55
56
56
class Inner :
57
- pass
57
+ ...
58
58
59
59
60
60
class B (Generic [T ]):
@@ -63,23 +63,32 @@ class B(Generic[T]):
63
63
64
64
65
65
class C (B [str ]):
66
- pass
66
+ ...
67
67
68
68
69
69
class D (typing_extensions .Protocol ):
70
- pass
70
+ ...
71
71
72
72
73
73
class E (typing_extensions .Protocol [T ]): # type: ignore # Invariant type variable "T" used in protocol where covariant
74
- pass
74
+ ...
75
75
76
76
77
77
class Slotted :
78
78
__slots__ = ()
79
79
80
80
81
81
class Metaclass (type ):
82
- pass
82
+ ...
83
+
84
+
85
+ class HintedMethods :
86
+ @classmethod
87
+ def from_magic (cls : type [T ]) -> T :
88
+ ...
89
+
90
+ def method (self : T ) -> T :
91
+ ...
83
92
84
93
85
94
PY310_PLUS = sys .version_info >= (3 , 10 )
@@ -673,13 +682,13 @@ def test_normalize_source_lines_async_def() -> None:
673
682
source = """
674
683
async def async_function():
675
684
class InnerClass:
676
- def __init__(self): pass
685
+ def __init__(self): ...
677
686
"""
678
687
679
688
expected = """
680
689
async def async_function():
681
690
class InnerClass:
682
- def __init__(self): pass
691
+ def __init__(self): ...
683
692
"""
684
693
685
694
assert normalize_source_lines (dedent (source )) == dedent (expected )
@@ -699,7 +708,7 @@ def test_normalize_source_lines_def_starting_decorator_parameter() -> None:
699
708
),
700
709
)
701
710
def __init__(bound_args): # noqa: N805
702
- pass
711
+ ...
703
712
"""
704
713
705
714
expected = """
@@ -715,7 +724,7 @@ def __init__(bound_args): # noqa: N805
715
724
),
716
725
)
717
726
def __init__(bound_args): # noqa: N805
718
- pass
727
+ ...
719
728
"""
720
729
721
730
assert normalize_source_lines (dedent (source )) == dedent (expected )
@@ -728,3 +737,17 @@ def test_default_no_signature(obj: Any) -> None:
728
737
lines : list [str ] = []
729
738
process_docstring (app , "what" , "name" , obj , None , lines )
730
739
assert lines == []
740
+
741
+
742
+ @pytest .mark .parametrize ("method" , [HintedMethods .from_magic , HintedMethods ().method ])
743
+ def test_bound_class_method (method : FunctionType ) -> None :
744
+ config = create_autospec (
745
+ Config ,
746
+ typehints_fully_qualified = False ,
747
+ simplify_optional_unions = False ,
748
+ typehints_document_rtype = False ,
749
+ always_document_param_types = True ,
750
+ typehints_defaults = True ,
751
+ )
752
+ app : Sphinx = create_autospec (Sphinx , config = config )
753
+ process_docstring (app , "class" , method .__qualname__ , method , None , [])
0 commit comments