File tree 3 files changed +18
-12
lines changed
test-data/stubgen/pybind11_mypy_demo
3 files changed +18
-12
lines changed Original file line number Diff line number Diff line change @@ -248,14 +248,19 @@ def infer_arg_sig_from_anon_docstring(docstr: str) -> List[ArgSig]:
248
248
return []
249
249
250
250
251
- def infer_ret_type_sig_from_anon_docstring (docstr : str ) -> Optional [str ]:
252
- """Convert signature in form of "(self: TestClass, arg0) -> int" to their return type."""
253
- ret = infer_sig_from_docstring ("stub" + docstr . strip (), "stub" )
251
+ def infer_ret_type_sig_from_docstring (docstr : str , name : str ) -> Optional [str ]:
252
+ """Convert signature in form of "func (self: TestClass, arg0) -> int" to their return type."""
253
+ ret = infer_sig_from_docstring (docstr , name )
254
254
if ret :
255
255
return ret [0 ].ret_type
256
256
return None
257
257
258
258
259
+ def infer_ret_type_sig_from_anon_docstring (docstr : str ) -> Optional [str ]:
260
+ """Convert signature in form of "(self: TestClass, arg0) -> int" to their return type."""
261
+ return infer_ret_type_sig_from_docstring ("stub" + docstr .strip (), "stub" )
262
+
263
+
259
264
def parse_signature (sig : str ) -> Optional [Tuple [str ,
260
265
List [str ],
261
266
List [str ]]]:
Original file line number Diff line number Diff line change 14
14
from mypy .moduleinspect import is_c_module
15
15
from mypy .stubdoc import (
16
16
infer_sig_from_docstring , infer_prop_type_from_docstring , ArgSig ,
17
- infer_arg_sig_from_anon_docstring , infer_ret_type_sig_from_anon_docstring , FunctionSig
17
+ infer_arg_sig_from_anon_docstring , infer_ret_type_sig_from_anon_docstring ,
18
+ infer_ret_type_sig_from_docstring , FunctionSig
18
19
)
19
20
20
21
# Members of the typing module to consider for importing by default.
@@ -254,6 +255,8 @@ def infer_prop_type(docstr: Optional[str]) -> Optional[str]:
254
255
"""Infer property type from docstring or docstring signature."""
255
256
if docstr is not None :
256
257
inferred = infer_ret_type_sig_from_anon_docstring (docstr )
258
+ if not inferred :
259
+ inferred = infer_ret_type_sig_from_docstring (docstr , name )
257
260
if not inferred :
258
261
inferred = infer_prop_type_from_docstring (docstr )
259
262
return inferred
Original file line number Diff line number Diff line change 1
- from typing import Any
2
-
3
1
from typing import overload
4
2
PI : float
5
3
@@ -17,11 +15,11 @@ class Point:
17
15
def __ne__ (self , other : object ) -> bool : ...
18
16
def __setstate__ (self , state : int ) -> None : ...
19
17
@property
20
- def name (self ) -> Any : ...
18
+ def name (self ) -> str : ...
21
19
@property
22
- def __doc__ (self ) -> Any : ...
20
+ def __doc__ (self ) -> str : ...
23
21
@property
24
- def __members__ (self ) -> Any : ...
22
+ def __members__ (self ) -> dict : ...
25
23
26
24
class LengthUnit :
27
25
__entries : dict = ...
@@ -37,11 +35,11 @@ class Point:
37
35
def __ne__ (self , other : object ) -> bool : ...
38
36
def __setstate__ (self , state : int ) -> None : ...
39
37
@property
40
- def name (self ) -> Any : ...
38
+ def name (self ) -> str : ...
41
39
@property
42
- def __doc__ (self ) -> Any : ...
40
+ def __doc__ (self ) -> str : ...
43
41
@property
44
- def __members__ (self ) -> Any : ...
42
+ def __members__ (self ) -> dict : ...
45
43
origin : Point = ...
46
44
@overload
47
45
def __init__ (self ) -> None : ...
You can’t perform that action at this time.
0 commit comments