Revert "Remove unused _pytest.code.Source.isparseable function"

This reverts commit c627ac4e59.
This commit is contained in:
Bruno Oliveira
2020-01-05 14:12:40 -03:00
parent 0fa35960ba
commit 12f74a28fa
3 changed files with 30 additions and 1 deletions

View File

@@ -136,6 +136,26 @@ class Source:
newsource.lines[:] = deindent(self.lines)
return newsource
def isparseable(self, deindent: bool = True) -> bool:
""" return True if source is parseable, heuristically
deindenting it by default.
"""
from parser import suite as syntax_checker
if deindent:
source = str(self.deindent())
else:
source = str(self)
try:
# compile(source+'\n', "x", "exec")
syntax_checker(source + "\n")
except KeyboardInterrupt:
raise
except Exception:
return False
else:
return True
def __str__(self) -> str:
return "\n".join(self.lines)