Skip to content

Commit 5a11701

Browse files
committed
Fix lgtm / codeql issues
1 parent 63e4329 commit 5a11701

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

src/lazydocs/generation.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import re
1010
import subprocess
1111
import types
12-
from inspect import getdoc, getmembers, getsourcefile, getsourcelines
1312
from pydoc import locate
1413
from typing import Any, Callable, Dict, List, Optional
1514

@@ -275,7 +274,7 @@ def __init__(
275274
def _get_line_no(self, obj: Any) -> Optional[int]:
276275
"""Gets the source line number of this object. None if `obj` code cannot be found."""
277276
try:
278-
return getsourcelines(obj)[1]
277+
return inspect.getsourcelines(obj)[1]
279278
except Exception:
280279
# no code found
281280
return None
@@ -298,7 +297,7 @@ def _get_src_path(self, obj: Any, append_base: bool = True) -> str:
298297
return ""
299298

300299
try:
301-
path = os.path.abspath(getsourcefile(obj)) # type: ignore
300+
path = os.path.abspath(inspect.getsourcefile(obj)) # type: ignore
302301
except Exception:
303302
return ""
304303

@@ -329,7 +328,7 @@ def _get_src_path(self, obj: Any, append_base: bool = True) -> str:
329328
return relative_path
330329

331330
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 ""
333332
# First line should contain the summary
334333
return doc.split("\n")[0]
335334

@@ -356,7 +355,7 @@ def doc2md(self, obj: Any) -> str:
356355
# the documentation strings are now inherited if not overridden.
357356
# For details see: https://docs.python.org/3.6/library/inspect.html#inspect.getdoc
358357
# 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 ""
360359

361360
blockindent = 0
362361
argindent = 1
@@ -575,7 +574,7 @@ def class2md(self, cls: Any, depth: int = 2) -> str:
575574
init = ""
576575

577576
variables = []
578-
for name, obj in getmembers(
577+
for name, obj in inspect.getmembers(
579578
cls, lambda a: not (inspect.isroutine(a) or inspect.ismethod(a))
580579
):
581580
if not name.startswith("_") and type(obj) == property:
@@ -590,7 +589,7 @@ def class2md(self, cls: Any, depth: int = 2) -> str:
590589
)
591590

592591
handlers = []
593-
for name, obj in getmembers(cls, inspect.ismethoddescriptor):
592+
for name, obj in inspect.getmembers(cls, inspect.ismethoddescriptor):
594593
if not name.startswith("_") and hasattr(
595594
obj, "__module__"
596595
): # and obj.__module__ == modname:
@@ -604,7 +603,7 @@ def class2md(self, cls: Any, depth: int = 2) -> str:
604603

605604
methods = []
606605
# for name, obj in getmembers(cls, inspect.isfunction):
607-
for name, obj in getmembers(
606+
for name, obj in inspect.getmembers(
608607
cls, lambda a: inspect.ismethod(a) or inspect.isfunction(a)
609608
):
610609
if (
@@ -660,7 +659,7 @@ def module2md(self, module: types.ModuleType, depth: int = 1) -> str:
660659

661660
classes: List[str] = []
662661
line_nos: List[int] = []
663-
for name, obj in getmembers(module, inspect.isclass):
662+
for name, obj in inspect.getmembers(module, inspect.isclass):
664663
# handle classes
665664
found.append(name)
666665
if (
@@ -674,7 +673,7 @@ def module2md(self, module: types.ModuleType, depth: int = 1) -> str:
674673

675674
functions: List[str] = []
676675
line_nos = []
677-
for name, obj in getmembers(module, inspect.isfunction):
676+
for name, obj in inspect.getmembers(module, inspect.isfunction):
678677
# handle functions
679678
found.append(name)
680679
if (
@@ -846,7 +845,7 @@ def generate_docs(
846845

847846
pydocstyle_cmd = "pydocstyle --convention=google --add-ignore=D100,D101,D102,D103,D104,D105,D107,D202"
848847

849-
for path in paths:
848+
for path in paths: # lgtm [py/non-iterable-in-for-loop]
850849
if os.path.isdir(path):
851850
if validate and subprocess.call(f"{pydocstyle_cmd} {path}", shell=True) > 0:
852851
raise Exception(f"Validation for {path} failed.")
@@ -855,7 +854,7 @@ def generate_docs(
855854
print(f"Generating docs for python package at: {path}")
856855
# Generate one file for every discovered module
857856
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]
859858
continue
860859

861860
if module_name.split(".")[-1].startswith("_"):

0 commit comments

Comments
 (0)