code/source: remove support for passing multiple parts to Source
It isn't used, so keep it simple.
This commit is contained in:
parent
c83e16ab2e
commit
2b99bfbc60
|
@ -8,10 +8,10 @@ import warnings
|
||||||
from bisect import bisect_right
|
from bisect import bisect_right
|
||||||
from types import CodeType
|
from types import CodeType
|
||||||
from types import FrameType
|
from types import FrameType
|
||||||
|
from typing import Iterable
|
||||||
from typing import Iterator
|
from typing import Iterator
|
||||||
from typing import List
|
from typing import List
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
from typing import Sequence
|
|
||||||
from typing import Tuple
|
from typing import Tuple
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
|
@ -32,21 +32,17 @@ class Source:
|
||||||
|
|
||||||
_compilecounter = 0
|
_compilecounter = 0
|
||||||
|
|
||||||
def __init__(self, *parts) -> None:
|
def __init__(self, obj: object = None) -> None:
|
||||||
self.lines = lines = [] # type: List[str]
|
if not obj:
|
||||||
for part in parts:
|
self.lines = [] # type: List[str]
|
||||||
if not part:
|
elif isinstance(obj, Source):
|
||||||
partlines = [] # type: List[str]
|
self.lines = obj.lines
|
||||||
elif isinstance(part, Source):
|
elif isinstance(obj, (tuple, list)):
|
||||||
partlines = part.lines
|
self.lines = deindent(x.rstrip("\n") for x in obj)
|
||||||
elif isinstance(part, (tuple, list)):
|
elif isinstance(obj, str):
|
||||||
partlines = [x.rstrip("\n") for x in part]
|
self.lines = deindent(obj.split("\n"))
|
||||||
elif isinstance(part, str):
|
|
||||||
partlines = part.split("\n")
|
|
||||||
else:
|
else:
|
||||||
partlines = getsource(part).lines
|
self.lines = deindent(getsource(obj).lines)
|
||||||
partlines = deindent(partlines)
|
|
||||||
lines.extend(partlines)
|
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
try:
|
try:
|
||||||
|
@ -312,7 +308,7 @@ def getsource(obj) -> Source:
|
||||||
return Source(strsrc)
|
return Source(strsrc)
|
||||||
|
|
||||||
|
|
||||||
def deindent(lines: Sequence[str]) -> List[str]:
|
def deindent(lines: Iterable[str]) -> List[str]:
|
||||||
return textwrap.dedent("\n".join(lines)).splitlines()
|
return textwrap.dedent("\n".join(lines)).splitlines()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue