9
9
import re
10
10
import subprocess
11
11
import types
12
- from inspect import getdoc , getmembers , getsourcefile , getsourcelines
13
12
from pydoc import locate
14
13
from typing import Any , Callable , Dict , List , Optional
15
14
@@ -275,7 +274,7 @@ def __init__(
275
274
def _get_line_no (self , obj : Any ) -> Optional [int ]:
276
275
"""Gets the source line number of this object. None if `obj` code cannot be found."""
277
276
try :
278
- return getsourcelines (obj )[1 ]
277
+ return inspect . getsourcelines (obj )[1 ]
279
278
except Exception :
280
279
# no code found
281
280
return None
@@ -298,7 +297,7 @@ def _get_src_path(self, obj: Any, append_base: bool = True) -> str:
298
297
return ""
299
298
300
299
try :
301
- path = os .path .abspath (getsourcefile (obj )) # type: ignore
300
+ path = os .path .abspath (inspect . getsourcefile (obj )) # type: ignore
302
301
except Exception :
303
302
return ""
304
303
@@ -329,7 +328,7 @@ def _get_src_path(self, obj: Any, append_base: bool = True) -> str:
329
328
return relative_path
330
329
331
330
def _get_doc_summary (self , obj : Any ) -> str :
332
- doc = "" if obj .__doc__ is None else getdoc (obj ) or ""
331
+ doc = "" if obj .__doc__ is None else inspect . getdoc (obj ) or ""
333
332
# First line should contain the summary
334
333
return doc .split ("\n " )[0 ]
335
334
@@ -356,7 +355,7 @@ def doc2md(self, obj: Any) -> str:
356
355
# the documentation strings are now inherited if not overridden.
357
356
# For details see: https://docs.python.org/3.6/library/inspect.html#inspect.getdoc
358
357
# doc = getdoc(func) or ""
359
- doc = "" if obj .__doc__ is None else getdoc (obj ) or ""
358
+ doc = "" if obj .__doc__ is None else inspect . getdoc (obj ) or ""
360
359
361
360
blockindent = 0
362
361
argindent = 1
@@ -575,7 +574,7 @@ def class2md(self, cls: Any, depth: int = 2) -> str:
575
574
init = ""
576
575
577
576
variables = []
578
- for name , obj in getmembers (
577
+ for name , obj in inspect . getmembers (
579
578
cls , lambda a : not (inspect .isroutine (a ) or inspect .ismethod (a ))
580
579
):
581
580
if not name .startswith ("_" ) and type (obj ) == property :
@@ -590,7 +589,7 @@ def class2md(self, cls: Any, depth: int = 2) -> str:
590
589
)
591
590
592
591
handlers = []
593
- for name , obj in getmembers (cls , inspect .ismethoddescriptor ):
592
+ for name , obj in inspect . getmembers (cls , inspect .ismethoddescriptor ):
594
593
if not name .startswith ("_" ) and hasattr (
595
594
obj , "__module__"
596
595
): # and obj.__module__ == modname:
@@ -604,7 +603,7 @@ def class2md(self, cls: Any, depth: int = 2) -> str:
604
603
605
604
methods = []
606
605
# for name, obj in getmembers(cls, inspect.isfunction):
607
- for name , obj in getmembers (
606
+ for name , obj in inspect . getmembers (
608
607
cls , lambda a : inspect .ismethod (a ) or inspect .isfunction (a )
609
608
):
610
609
if (
@@ -660,7 +659,7 @@ def module2md(self, module: types.ModuleType, depth: int = 1) -> str:
660
659
661
660
classes : List [str ] = []
662
661
line_nos : List [int ] = []
663
- for name , obj in getmembers (module , inspect .isclass ):
662
+ for name , obj in inspect . getmembers (module , inspect .isclass ):
664
663
# handle classes
665
664
found .append (name )
666
665
if (
@@ -674,7 +673,7 @@ def module2md(self, module: types.ModuleType, depth: int = 1) -> str:
674
673
675
674
functions : List [str ] = []
676
675
line_nos = []
677
- for name , obj in getmembers (module , inspect .isfunction ):
676
+ for name , obj in inspect . getmembers (module , inspect .isfunction ):
678
677
# handle functions
679
678
found .append (name )
680
679
if (
@@ -846,7 +845,7 @@ def generate_docs(
846
845
847
846
pydocstyle_cmd = "pydocstyle --convention=google --add-ignore=D100,D101,D102,D103,D104,D105,D107,D202"
848
847
849
- for path in paths :
848
+ for path in paths : # lgtm [py/non-iterable-in-for-loop]
850
849
if os .path .isdir (path ):
851
850
if validate and subprocess .call (f"{ pydocstyle_cmd } { path } " , shell = True ) > 0 :
852
851
raise Exception (f"Validation for { path } failed." )
@@ -855,7 +854,7 @@ def generate_docs(
855
854
print (f"Generating docs for python package at: { path } " )
856
855
# Generate one file for every discovered module
857
856
for loader , module_name , is_pkg in pkgutil .walk_packages ([path ]):
858
- if module_name in ignored_modules :
857
+ if module_name in ignored_modules : # lgtm [py/non-iterable-in-for-loop]
859
858
continue
860
859
861
860
if module_name .split ("." )[- 1 ].startswith ("_" ):
0 commit comments