-
Notifications
You must be signed in to change notification settings - Fork 372
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Turn off syntax highlighting of hy expressions by default #1510
Comments
See also #1429. |
See also #1360. There are ways to turn this off, but if it wasn't the default, many users would never notice the feature even exists. That was my rationale for making pretty opt-out instead of opt-in. We could also perhaps add a command-line switch or environment variable to turn this off. |
I think turning it on by default inside the REPL is great, but my concern is more so that it leaks outside the context and creates a something less readable. Hy objects will cross the Python boundry: >>> foo = hy.HyExpression([hy.HySymbol('foo')])
>>> repr(foo)
"\x1b[33m\x1b[22mHyExpression\x1b[39m\x1b[22m\x1b[33m\x1b[22m([\x1b[39m\x1b[22m\n HySymbol('foo')\x1b[33m\x1b[22m])\x1b[39m\x1b[22m" What happens if I'm logging exceptions with context and there's a Hy expression? Now there's noise I have to strip out Here's another example where it creates noise in pytest:
pytest correctly strips escape sequences, but the newline characters are literally printed and, imho, impede understanding. Because technically we're abusing repr. And looking at #1360, @kirbyfan64 properly points out this:
But the escape sequences prevent round tripping from working. |
So, how do you want this to work? It does round-trip if you copy-paste in most terminals, since the coloring doesn't make it into the system clipboard. This is the usual use case for round-tripping. You can also strip the color codes programmatically using clint if you need to eval a string repr for some reason. But this seems rarely useful. In your Python repr example, you're using internal Hy models directly in a python repl. If you're creating Hy modules to be consumed from Python, you won't be exporting this stuff. Even then, making it readable in the console is as simple as I said before that managing this kind of thing would be easier with dynamic vars hylang/hyrule#51. But until that's implemented we have to settle for a module-level global. We could have Hy doesn't have a debugger of its own, but is mostly compatible with pdb, so it would be nice if the Hy model reprs were pretty there too. Repl startup activation would prevent the Python repl from getting the pretty reprs. But it might also prevent certain uses of pdb. You can turn it back on every time, of course, but this is inconvenient. Hence my environment variable suggestion. There might also be cases where we'd want to launch a Hy repl from a Python repl. #1323. The embedded Hy repl could also turn PRETTY on, but if you quit back to python, PRETTY would still be on. Maybe you could turn it off at exit. If it doesn't crash. |
As for the Pytest example, pytest needs special instructions to find Hy files in the first place. Whatever setup code is doing that could also turn off PRETTY. But I don't know that it improves readability that much. For a simple |
This commit refactors the exception/error classes and their handling, keeps Hy source string and their originating file (if any) information closer to the origin of an exception (so that calling code isn't responsible for annotating exceptions), and provides minimally intrusive traceback print-out filtering via a context manager that temporarily alters `sys.excepthook`. It also provides an environment variable, `HY_COLORED_ERRORS`, and package variable, `hy.errors.__colored_errors`, that enables/disables manual error coloring. Closes hylang#657, closes hylang#1510, closes hylang#1429.
This commit refactors the exception/error classes and their handling, keeps Hy source strings and their originating file (if any) information closer to the origin of an exception (so that calling code isn't responsible for annotating exceptions), and provides minimally intrusive traceback print-out filtering via a context manager that temporarily alters `sys.excepthook` (enabled by default for the Hy interpreter). It also provides an environment variable, `HY_COLORED_ERRORS`, and package variable, `hy.errors.__colored_errors`, that enables/disables manual error coloring. Closes hylang#657, closes hylang#1510, closes hylang#1429.
This commit refactors the exception/error classes and their handling, keeps Hy source strings and their originating file information (if any) closer to the origin of an exception (so that calling code isn't responsible for annotating exceptions), and provides minimally intrusive traceback print-out filtering via a context manager that temporarily alters `sys.excepthook` (enabled by default for the Hy interpreter). It also provides an environment variable, `HY_COLORED_ERRORS`, and package variable, `hy.errors.__colored_errors`, that enables/disables manual error coloring. Closes hylang#657, closes hylang#1510, closes hylang#1429.
This commit refactors the exception/error classes and their handling, keeps Hy source strings and their originating file information (if any) closer to the origin of an exception (so that calling code isn't responsible for annotating exceptions), and provides minimally intrusive traceback print-out filtering via a context manager that temporarily alters `sys.excepthook` (enabled by default for the Hy interpreter). It also provides an environment variable, `HY_COLORED_ERRORS`, and package variable, `hy.errors.__colored_errors`, that enables/disables manual error coloring. Closes hylang#657, closes hylang#1510, closes hylang#1429.
This commit refactors the exception/error classes and their handling, keeps Hy source strings and their originating file information (if any) closer to the origin of an exception (so that calling code isn't responsible for annotating exceptions), and provides minimally intrusive traceback print-out filtering via a context manager that temporarily alters `sys.excepthook` (enabled by default for the Hy interpreter). It also provides an environment variable, `HY_COLORED_ERRORS`, and package variable, `hy.errors.__colored_errors`, that enables/disables manual error coloring. Closes hylang#657, closes hylang#1510, closes hylang#1429.
This commit refactors the exception/error classes and their handling, keeps Hy source strings and their originating file information (if any) closer to the origin of an exception (so that calling code isn't responsible for annotating exceptions), and provides minimally intrusive traceback print-out filtering via a context manager that temporarily alters `sys.excepthook` (enabled by default for the Hy interpreter). It also provides an environment variable, `HY_COLORED_ERRORS`, and package variable, `hy.errors.__colored_errors`, that enables/disables manual error coloring. Closes hylang#657, closes hylang#1510, closes hylang#1429.
This commit refactors the exception/error classes and their handling, keeps Hy source strings and their originating file information (if any) closer to the origin of an exception (so that calling code isn't responsible for annotating exceptions), and provides minimally intrusive traceback print-out filtering via a context manager that temporarily alters `sys.excepthook` (enabled by default for the Hy interpreter). It also provides an environment variable, `HY_COLORED_ERRORS`, and package variable, `hy.errors.__colored_errors`, that enables/disables manual error coloring. Closes hylang#657, closes hylang#1510, closes hylang#1429.
This commit refactors the exception/error classes and their handling, keeps Hy source strings and their originating file information (if any) closer to the origin of an exception (so that calling code isn't responsible for annotating exceptions), and provides minimally intrusive traceback print-out filtering via a context manager that temporarily alters `sys.excepthook` (enabled by default for the Hy interpreter). It also provides an environment variable, `HY_COLORED_ERRORS`, and package variable, `hy.errors.__colored_errors`, that enables/disables manual error coloring. Closes hylang#657, closes hylang#1510, closes hylang#1429.
Colored exception output is now disabled by default and configurable through `hy.errors._hy_colored_errors` and the environment variable `HY_FILTER_INTERNAL_ERRORS`. Likewise, Hy model/AST color printing is now configurable and disabled by default. The corresponding variables are `hy.models._hy_colored_ast_objects` and `HY_COLORED_AST_OBJECTS`. Closes hylang#1429, closes hylang#1510.
Colored exception output is now disabled by default and configurable through `hy.errors._hy_colored_errors` and the environment variable `HY_FILTER_INTERNAL_ERRORS`. Likewise, Hy model/AST color printing is now configurable and disabled by default. The corresponding variables are `hy.models._hy_colored_ast_objects` and `HY_COLORED_AST_OBJECTS`. Closes hylang#1429, closes hylang#1510.
Colored exception output is now disabled by default and configurable through `hy.errors._hy_colored_errors` and the environment variable `HY_FILTER_INTERNAL_ERRORS`. Likewise, Hy model/AST color printing is now configurable and disabled by default. The corresponding variables are `hy.models._hy_colored_ast_objects` and `HY_COLORED_AST_OBJECTS`. Closes hylang#1429, closes hylang#1510.
Colored exception output is now disabled by default and configurable through `hy.errors._hy_colored_errors` and the environment variable `HY_FILTER_INTERNAL_ERRORS`. Likewise, Hy model/AST color printing is now configurable and disabled by default. The corresponding variables are `hy.models._hy_colored_ast_objects` and `HY_COLORED_AST_OBJECTS`. Closes hylang#1429, closes hylang#1510.
Colored exception output is now disabled by default and configurable through `hy.errors._hy_colored_errors` and the environment variable `HY_FILTER_INTERNAL_ERRORS`. Likewise, Hy model/AST color printing is now configurable and disabled by default. The corresponding variables are `hy.models._hy_colored_ast_objects` and `HY_COLORED_AST_OBJECTS`. Closes hylang#1429, closes hylang#1510.
Colored exception output is now disabled by default and configurable through `hy.errors._hy_colored_errors` and the environment variable `HY_FILTER_INTERNAL_ERRORS`. Likewise, Hy model/AST color printing is now configurable and disabled by default. The corresponding variables are `hy.models._hy_colored_ast_objects` and `HY_COLORED_AST_OBJECTS`. Closes hylang#1429, closes hylang#1510.
Colored exception output is now disabled by default and configurable through `hy.errors._hy_colored_errors` and the environment variable `HY_FILTER_INTERNAL_ERRORS`. Likewise, Hy model/AST color printing is now configurable and disabled by default. The corresponding variables are `hy.models._hy_colored_ast_objects` and `HY_COLORED_AST_OBJECTS`. Closes hylang#1429, closes hylang#1510.
Colored exception output is now disabled by default and configurable through `hy.errors._hy_colored_errors` and the environment variable `HY_FILTER_INTERNAL_ERRORS`. Likewise, Hy model/AST color printing is now configurable and disabled by default. The corresponding variables are `hy.models._hy_colored_ast_objects` and `HY_COLORED_AST_OBJECTS`. Closes hylang#1429, closes hylang#1510.
Colored exception output is now disabled by default and configurable through `hy.errors._hy_colored_errors` and the environment variable `HY_FILTER_INTERNAL_ERRORS`. Likewise, Hy model/AST color printing is now configurable and disabled by default. The corresponding variables are `hy.models._hy_colored_ast_objects` and `HY_COLORED_AST_OBJECTS`. Closes hylang#1429, closes hylang#1510.
Colored exception output is now disabled by default and configurable through `hy.errors._hy_colored_errors` and the environment variable `HY_FILTER_INTERNAL_ERRORS`. Likewise, Hy model/AST color printing is now configurable and disabled by default. The corresponding variables are `hy.models._hy_colored_ast_objects` and `HY_COLORED_AST_OBJECTS`. Closes hylang#1429, closes hylang#1510.
Colored exception output is now disabled by default and configurable through `hy.errors._hy_colored_errors` and the environment variable `HY_FILTER_INTERNAL_ERRORS`. Likewise, Hy model/AST color printing is now configurable and disabled by default. The corresponding variables are `hy.models._hy_colored_ast_objects` and `HY_COLORED_AST_OBJECTS`. Closes hylang#1429, closes hylang#1510.
Colored exception output is now disabled by default and configurable through `hy.errors._hy_colored_errors` and the environment variable `HY_FILTER_INTERNAL_ERRORS`. Likewise, Hy model/AST color printing is now configurable and disabled by default. The corresponding variables are `hy.models._hy_colored_ast_objects` and `HY_COLORED_AST_OBJECTS`. Closes hylang#1429, closes hylang#1510.
Colored exception output is now disabled by default and configurable through `hy.errors._hy_colored_errors` and the environment variable `HY_COLORED_ERRORS`. Likewise, Hy model/AST color printing is now configurable and disabled by default. The corresponding variables are `hy.models._hy_colored_ast_objects` and `HY_COLORED_AST_OBJECTS`. Closes hylang#1429, closes hylang#1510.
Colored exception output is now disabled by default and configurable through `hy.errors._hy_colored_errors` and the environment variable `HY_COLORED_ERRORS`. Likewise, Hy model/AST color printing is now configurable and disabled by default. The corresponding variables are `hy.models._hy_colored_ast_objects` and `HY_COLORED_AST_OBJECTS`. Closes hylang#1429, closes hylang#1510.
Colored exception output is now disabled by default and configurable through `hy.errors._hy_colored_errors` and the environment variable `HY_COLORED_ERRORS`. Likewise, Hy model/AST color printing is now configurable and disabled by default. The corresponding variables are `hy.models._hy_colored_ast_objects` and `HY_COLORED_AST_OBJECTS`. Closes hylang#1429, closes hylang#1510.
Colored exception output is now disabled by default and configurable through `hy.errors._hy_colored_errors` and the environment variable `HY_COLORED_ERRORS`. Likewise, Hy model/AST color printing is now configurable and disabled by default. The corresponding variables are `hy.models._hy_colored_ast_objects` and `HY_COLORED_AST_OBJECTS`. Closes hylang#1429, closes hylang#1510.
The pretty printing is nice, and having the basic syntax highlighting to emphasis opening and closing brackets for
HyExpression
andHyList
is certainly cool.But I'm looking at embedding
hy
support in some of my Python projects and the ANSI colour codes are leaking into error messages, making them less legible. This should be opt-in feature of the REPL, not a default.The text was updated successfully, but these errors were encountered: