Enhancements to running code in a terminal#1432
Enhancements to running code in a terminal#1432DonJayamanne merged 12 commits intomicrosoft:masterfrom
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1432 +/- ##
===========================================
- Coverage 70.8% 45.29% -25.52%
===========================================
Files 271 271
Lines 12519 12550 +31
Branches 2224 2231 +7
===========================================
- Hits 8864 5684 -3180
- Misses 3512 6716 +3204
- Partials 143 150 +7
Continue to review full report at Codecov.
|
|
@brettcannon Please review. See #259 for details. Oh yes, this will require a lot of testing. |
brettcannon
left a comment
There was a problem hiding this comment.
I would also add a test that includes UTF-8 Unicode characters.
| unicode = str | ||
|
|
||
|
|
||
| def normalizeLines(content): |
|
|
||
|
|
||
| def normalizeLines(content): | ||
| """Removes empty lines and adds empty lines only to sepaparate |
There was a problem hiding this comment.
Docstrings always have a single line summary that fits within the 80 column limit, then a newline, then anything extra. E.g.
def normalize_lines(content):
"""Normalize blank lines for sending to the terminal.
Blank lines within a statement block are removed to prevent the REPL
from thinking the block is finished. Newlines are added to separate
top-level statements so that the REPL does not think there is a syntax
error.
"""
lines = content.splitlines(False)
# ...|
|
||
| lines = content.splitlines(False) | ||
|
|
||
| # Find out if we have any trailing blank lines |
| # Find out if we have any trailing blank lines | ||
| has_blank_lines = len(lines[-1].strip()) == 0 or content.endswith(os.linesep) | ||
|
|
||
| # Remove empty lines |
| for line_index in reversed(new_lines_to_remove): | ||
| lines.pop(line_index) | ||
|
|
||
| # Add new lines just before every dedent |
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| contents = unicode(sys.argv[1]) |
There was a problem hiding this comment.
What are you trying to accomplish here? This is a rather dramatic decoding if you were handed bytes through sys.argv.
There was a problem hiding this comment.
When sending via stdin for python2, bytes get sent in stdin.
| has_blank_lines = len(lines[-1].strip()) == 0 or content.endswith(os.linesep) | ||
|
|
||
| # Remove empty lines | ||
| tokens = tokenize.generate_tokens(io.StringIO(content).readline) |
There was a problem hiding this comment.
FYI that is undocumented in Python 3. Is there a reason you aren't using tokenize.tokenize()?
Fixes #1207
Fixes #1316
Fixes #1349
Fixes #259
This pull request: