code/source: inline getsource()
The recursive way in which Source and getsource interact is a bit confusing, just inline it.
This commit is contained in:
@@ -30,7 +30,9 @@ class Source:
|
||||
elif isinstance(obj, str):
|
||||
self.lines = deindent(obj.split("\n"))
|
||||
else:
|
||||
self.lines = deindent(getsource(obj).lines)
|
||||
rawcode = getrawcode(obj)
|
||||
src = inspect.getsource(rawcode)
|
||||
self.lines = deindent(src.split("\n"))
|
||||
|
||||
def __eq__(self, other: object) -> bool:
|
||||
if not isinstance(other, Source):
|
||||
@@ -141,12 +143,6 @@ def getrawcode(obj, trycall: bool = True):
|
||||
return obj
|
||||
|
||||
|
||||
def getsource(obj) -> Source:
|
||||
obj = getrawcode(obj)
|
||||
strsrc = inspect.getsource(obj)
|
||||
return Source(strsrc)
|
||||
|
||||
|
||||
def deindent(lines: Iterable[str]) -> List[str]:
|
||||
return textwrap.dedent("\n".join(lines)).splitlines()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user