Repository: hauntsaninja/pyp

Issue:
`AssertionError: The command doesn't process input, but input is present` on `sys.stdin` usage
I was trying to read bytes instead of string from stdin for #27, but got this:

```shell
$ echo pyp | pyp "sys.stdin"
error: Code raised the following exception, consider using --explain to investigate:

Possible reconstructed traceback (most recent call last):
  File "<pyp>", in <module>
    assert sys.stdin.isatty() or not sys.stdin.read(), "The command doesn't process input, but input is present"
AssertionError: The command doesn't process input, but input is present
```
```shell
$ echo 1 | pyp "sys.stdin" --explain
#!/usr/bin/env python3
import sys
from pyp import pypprint
assert sys.stdin.isatty() or not sys.stdin.read(), "The command doesn't process input, but input is present"
output = sys.stdin
if output is not None:
    pypprint(output)
```


Discussion:

Patch:
diff --git a/pyp.py b/pyp.py
index b1e1614..b97cb25 100644
--- a/pyp.py
+++ b/pyp.py
@@ -512,7 +512,8 @@ class PypTransform:
         else:
             no_pipe_assertion = ast.parse(
                 "assert sys.stdin.isatty() or not sys.stdin.read(), "
-                '''"The command doesn't process input, but input is present"'''
+                """"The command doesn't process input, but input is present. """
+                '''Maybe you meant to use a magic variable like `stdin` or `x`?"'''
             )
             self.tree.body = no_pipe_assertion.body + self.tree.body
             self.use_pypprint_for_implicit_print()


Test patch:
diff --git a/tests/test_pyp.py b/tests/test_pyp.py
index 742c604..106f85e 100644
--- a/tests/test_pyp.py
+++ b/tests/test_pyp.py
@@ -285,7 +285,7 @@ def test_wildcard_import():
 #!/usr/bin/env python3
 from shlex import split
 import sys
-assert sys.stdin.isatty() or not sys.stdin.read(), "The command doesn't process input, but input is present"
+assert sys.stdin.isatty() or not sys.stdin.read(), "The command doesn't process input, but input is present. Maybe you meant to use a magic variable like `stdin` or `x`?"
 from shlex import *
 split
 """  # noqa
@@ -295,7 +295,7 @@ split
 #!/usr/bin/env python3
 from shlex import split
 import sys
-assert sys.stdin.isatty() or not sys.stdin.read(), "The command doesn't process input, but input is present"
+assert sys.stdin.isatty() or not sys.stdin.read(), "The command doesn't process input, but input is present. Maybe you meant to use a magic variable like `stdin` or `x`?"
 from os.path import *
 from shlex import *
 split
@@ -347,7 +347,7 @@ np
 import sys
 import numpy as np
 from scipy.linalg import eigvals
-assert sys.stdin.isatty() or not sys.stdin.read(), "The command doesn't process input, but input is present"
+assert sys.stdin.isatty() or not sys.stdin.read(), "The command doesn't process input, but input is present. Maybe you meant to use a magic variable like `stdin` or `x`?"
 eigvals(np.array([[0.0, -1.0], [1.0, 0.0]]))
 """  # noqa
     compare_scripts(
@@ -542,7 +542,7 @@ def test_config_automatic_import(config_mock):
 import json
 import sys
 j = json
-assert sys.stdin.isatty() or not sys.stdin.read(), "The command doesn't process input, but input is present"
+assert sys.stdin.isatty() or not sys.stdin.read(), "The command doesn't process input, but input is present. Maybe you meant to use a magic variable like `stdin` or `x`?"
 j
 """  # noqa
     compare_scripts(run_pyp(["--explain", "j; pass"]), script1)
@@ -553,7 +553,7 @@ j
 from typing import List
 import sys
 L = List
-assert sys.stdin.isatty() or not sys.stdin.read(), "The command doesn't process input, but input is present"
+assert sys.stdin.isatty() or not sys.stdin.read(), "The command doesn't process input, but input is present. Maybe you meant to use a magic variable like `stdin` or `x`?"
 L
 """  # noqa
     compare_scripts(run_pyp(["--explain", "L; pass"]), script2)
@@ -646,7 +646,7 @@ else:
 import ast
 import sys
 {if_block}
-assert sys.stdin.isatty() or not sys.stdin.read(), "The command doesn't process input, but input is present"
+assert sys.stdin.isatty() or not sys.stdin.read(), "The command doesn't process input, but input is present. Maybe you meant to use a magic variable like `stdin` or `x`?"
 unparse(ast.parse('x'))
 """  # noqa
     compare_scripts(run_pyp(["--explain", "unparse(ast.parse('x')); pass"]), script1)
@@ -664,7 +664,7 @@ except ImportError:
 import sys
 import ast
 {except_block}
-assert sys.stdin.isatty() or not sys.stdin.read(), "The command doesn't process input, but input is present"
+assert sys.stdin.isatty() or not sys.stdin.read(), "The command doesn't process input, but input is present. Maybe you meant to use a magic variable like `stdin` or `x`?"
 unparse(ast.parse('x'))
 """  # noqa
     compare_scripts(run_pyp(["--explain", "unparse(ast.parse('x')); pass"]), script2)
@@ -693,7 +693,7 @@ except ImportError:
 import sys
 import ast
 {except_block}
-assert sys.stdin.isatty() or not sys.stdin.read(), "The command doesn't process input, but input is present"
+assert sys.stdin.isatty() or not sys.stdin.read(), "The command doesn't process input, but input is present. Maybe you meant to use a magic variable like `stdin` or `x`?"
 unparse(ast.parse('x'))
 """  # noqa
     compare_scripts(run_pyp(["--explain", "unparse(ast.parse('x')); pass"]), script3)