diff --git a/hy/reader/exceptions.py b/hy/reader/exceptions.py index 1dadf055a..44d9e46fa 100644 --- a/hy/reader/exceptions.py +++ b/hy/reader/exceptions.py @@ -11,4 +11,4 @@ def from_reader(cls, message, reader): class PrematureEndOfInput(LexException): "Raised when input ends unexpectedly during parsing." - pass + __module__ = 'hy' diff --git a/hy/reader/hy_reader.py b/hy/reader/hy_reader.py index 451052e62..14b21bcdb 100644 --- a/hy/reader/hy_reader.py +++ b/hy/reader/hy_reader.py @@ -117,6 +117,8 @@ class HyReader(Reader): When ``use_current_readers`` is true, initialize this reader with all reader macros from the calling module.""" + __module__ = 'hy' + ### # Components necessary for Reader implementation ### diff --git a/hy/reader/reader.py b/hy/reader/reader.py index 21cd0b954..26a9a308b 100644 --- a/hy/reader/reader.py +++ b/hy/reader/reader.py @@ -58,6 +58,8 @@ class Reader(metaclass=ReaderMeta): A read-only (line, column) tuple indicating the current cursor position of the source being read""" + __module__ = 'hy' + def __init__(self): self._source = None self._filename = None diff --git a/hy/repl.py b/hy/repl.py index 22f012592..8f771e12c 100644 --- a/hy/repl.py +++ b/hy/repl.py @@ -247,6 +247,8 @@ class REPL(code.InteractiveConsole): Note that as with :func:`code.interact`, changes to local variables inside the REPL are not propagated back to the original scope.""" + __module__ = 'hy' + def __init__(self, spy=False, spy_delimiter=('-' * 30), output_fn=None, locals=None, filename="", allow_incomplete=True): # Create a proper module for this REPL so that we can obtain it easily @@ -460,6 +462,3 @@ def banner(self): pyversion=platform.python_version(), os=platform.system(), ) - - -REPL.__module__ = "hy" # Print as `hy.REPL` instead of `hy.repl.REPL`. diff --git a/tests/compilers/test_ast.py b/tests/compilers/test_ast.py index deea00ef0..351467a8d 100644 --- a/tests/compilers/test_ast.py +++ b/tests/compilers/test_ast.py @@ -8,7 +8,7 @@ from hy.compiler import hy_compile from hy.errors import HyError, HyLanguageError from hy.reader import read_many -from hy.reader.exceptions import LexException, PrematureEndOfInput +from hy.reader.exceptions import LexException def _ast_spotcheck(arg, root, secondary): @@ -466,7 +466,7 @@ def test_compile_error(): def test_for_compile_error(): """Ensure we get compile error in tricky 'for' cases""" - with pytest.raises(PrematureEndOfInput) as excinfo: + with pytest.raises(hy.PrematureEndOfInput) as excinfo: can_compile("(fn [] (for)") assert excinfo.value.msg.startswith("Premature end of input") diff --git a/tests/importer/test_importer.py b/tests/importer/test_importer.py index 4a7d66c0c..10d2b76f1 100644 --- a/tests/importer/test_importer.py +++ b/tests/importer/test_importer.py @@ -12,7 +12,6 @@ from hy.errors import HyLanguageError, hy_exc_handler from hy.importer import HyLoader from hy.reader import read_many -from hy.reader.exceptions import PrematureEndOfInput def test_basics(): @@ -183,7 +182,7 @@ def unlink(filename): source.write_text("(setv a 11 (setv b (// 20 1))") - with pytest.raises(PrematureEndOfInput): + with pytest.raises(hy.PrematureEndOfInput): reload(mod) mod = sys.modules.get(TESTFN) @@ -266,7 +265,7 @@ def test_filtered_importlib_frames(capsys): spec = importlib.util.spec_from_loader(testLoader.name, testLoader) mod = importlib.util.module_from_spec(spec) - with pytest.raises(PrematureEndOfInput) as execinfo: + with pytest.raises(hy.PrematureEndOfInput) as execinfo: testLoader.exec_module(mod) hy_exc_handler(execinfo.type, execinfo.value, execinfo.tb) diff --git a/tests/native_tests/reader_macros.hy b/tests/native_tests/reader_macros.hy index cabd39dd9..20e0e70dc 100644 --- a/tests/native_tests/reader_macros.hy +++ b/tests/native_tests/reader_macros.hy @@ -4,8 +4,6 @@ types contextlib [contextmanager] hy.errors [HyMacroExpansionError] - hy.reader [HyReader] - hy.reader.exceptions [PrematureEndOfInput] pytest) @@ -55,7 +53,7 @@ (defn test-bad-reader-macro-name [] (with [(pytest.raises HyMacroExpansionError)] (eval-module "(defreader :a-key '1)")) - (with [(pytest.raises PrematureEndOfInput)] + (with [(pytest.raises hy.PrematureEndOfInput)] (eval-module "# _ 3"))) (defn test-get-macro [] @@ -123,7 +121,7 @@ (with [(pytest.raises hy.errors.HySyntaxError)] (hy.read tag))) ;; but they should be installed in the module - (hy.eval '(setv reader (hy.reader.HyReader :use-current-readers True)) :module module) + (hy.eval '(setv reader (hy.HyReader :use-current-readers True)) :module module) (setv reader module.reader) (for [[s val] [["#r" 5] ["#test-read" 4] @@ -132,7 +130,7 @@ ;; passing a reader explicitly should work as expected (with [module (temp-module "")] - (setv reader (HyReader)) + (setv reader (hy.HyReader)) (defn eval1 [s] (hy.eval (hy.read s :reader reader) :module module)) (eval1 "(defreader fbaz 32)") diff --git a/tests/test_bin.py b/tests/test_bin.py index d9a97ea13..5ff39fc2e 100644 --- a/tests/test_bin.py +++ b/tests/test_bin.py @@ -446,7 +446,7 @@ def req_err(x): r' File "(?:|string-[0-9a-f]+)", line 1\n' r' \(print "\n' r" \^\n" - r"hy.reader.exceptions.PrematureEndOfInput" + r"hy.PrematureEndOfInput" ) assert re.search(peoi_re, error) diff --git a/tests/test_reader.py b/tests/test_reader.py index 0ef34dc57..f7b7171ea 100644 --- a/tests/test_reader.py +++ b/tests/test_reader.py @@ -4,6 +4,7 @@ import pytest +from hy import PrematureEndOfInput from hy.errors import hy_exc_handler from hy.models import ( Bytes, @@ -20,7 +21,7 @@ Symbol, ) from hy.reader import read_many -from hy.reader.exceptions import LexException, PrematureEndOfInput +from hy.reader.exceptions import LexException def tokenize(*args, **kwargs): @@ -86,7 +87,7 @@ def test_lex_single_quote_err(): ' File "", line 1', " '", " ^", - "hy.reader.exceptions.PrematureEndOfInput: Premature end of input while attempting to parse one form", + "hy.PrematureEndOfInput: Premature end of input while attempting to parse one form", ], ) @@ -660,7 +661,7 @@ def test_lex_exception_filtering(capsys): ' File "", line 2', " (foo", " ^", - "hy.reader.exceptions.PrematureEndOfInput: Premature end of input while attempting to parse one form", + "hy.PrematureEndOfInput: Premature end of input while attempting to parse one form", ], ) @@ -702,3 +703,9 @@ def test_shebang(): assert tokenize('#!/usr/bin/env hy\n5') assert (tokenize('#!/usr/bin/env hy\n5', skip_shebang = True) == [Integer(5)]) + + +def test_reader_class_reprs(): + "Don't show internal modules in which these classes are defined." + assert repr(hy.Reader) == "" + assert repr(hy.HyReader) == ""