You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$ python3 teyit.py --show-stats t.pyiteration=0import unittestclass foo(unittest.TestCase): def testBar(self): print("testing") self.assertTrue("s" in "strings", "yay") print("testing done")calling astparse()iteration=1import unittestclass foo(unittest.TestCase): def testBar(self): print("testing") self.assertIn("s", "strings", "yay") print("testing done")calling astparse()Traceback (most recent call last): File "/Users/nega/Downloads/teyit/teyit.py", line 404, in <module> main() File "/Users/nega/Downloads/teyit/teyit.py", line 400, in main raise SystemExit(_refactor_files(**vars(options))) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/nega/Downloads/teyit/teyit.py", line 357, in _refactor_files if len(refactors := _refactor_file(path)) > 0: ^^^^^^^^^^^^^^^^^^^^ File "/Users/nega/Downloads/teyit/teyit.py", line 345, in _refactor_file refactored_source, refactors = refactor_until_deterministic( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/nega/Downloads/teyit/teyit.py", line 304, in refactor_until_deterministic source, _refactors = rewrite_source(source, blacklist=blacklist) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/nega/Downloads/teyit/teyit.py", line 272, in rewrite_source tree = ast.parse(source) ^^^^^^^^^^^^^^^^^ File "/opt/homebrew/Cellar/python@3.11/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/ast.py", line 50, in parse return compile(source, filename, mode, flags, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "<unknown>", line 6 self.assertIn("s", "strings", "yay") ^IndentationError: unindent does not match any outer indentation level
It looks like teyit is replacing "tab stops" with single spaces. Indeed that replacement is in as_source(). The column offset of our node is recorded, and the new code we're injecting is then indented by that many spaces (instead of that many "indent characters"). Not being that familiar with teyit or Python's ast, I don't see a clean way of getting the "indent character" into as_source().
The text was updated successfully, but these errors were encountered:
nega0
changed the title
teyit fails to handle tab-indented files
teyit assumes space-indented source
Aug 16, 2023
teyit
mishandles tab-indented source. Yeah, I know, tabs...Given the following test file:
and the following diff against
teyit.py
(for illustrative purposes):We get the following output
It looks like
teyit
is replacing "tab stops" with single spaces. Indeed that replacement is inas_source()
. The column offset of our node is recorded, and the new code we're injecting is then indented by that many spaces (instead of that many "indent characters"). Not being that familiar withteyit
or Python'sast
, I don't see a clean way of getting the "indent character" intoas_source()
.The text was updated successfully, but these errors were encountered: