From e48f92f0b011c153b642138b2a266f6cb2c2845c Mon Sep 17 00:00:00 2001 From: Kodi Arfer Date: Wed, 7 Jun 2023 13:40:25 -0400 Subject: [PATCH 1/2] Update a test that used a removed macro --- tests/macros/test_macro_processor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/macros/test_macro_processor.py b/tests/macros/test_macro_processor.py index 5fb317911..464dcca81 100644 --- a/tests/macros/test_macro_processor.py +++ b/tests/macros/test_macro_processor.py @@ -55,7 +55,7 @@ def test_macroexpand_nan(): def test_macroexpand_source_data(): # https://github.com/hylang/hy/issues/1944 - ast = Expression([Symbol("#@"), String("a")]) + ast = Expression([Symbol("when"), String("a")]) ast.start_line = 3 ast.start_column = 5 bad = macroexpand_1(ast, "hy.core.macros") From 9916b7d18a675506944a8bad81c1d35916a919a0 Mon Sep 17 00:00:00 2001 From: Kodi Arfer Date: Wed, 7 Jun 2023 13:49:15 -0400 Subject: [PATCH 2/2] Forbid `Symbol("#foo")` --- NEWS.rst | 2 ++ hy/reader/hy_reader.py | 2 +- tests/test_models.py | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/NEWS.rst b/NEWS.rst index cbd903774..d4765e986 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -29,6 +29,8 @@ Bug Fixes * The parser no longer looks for shebangs in the REPL or `hy -c`. * `require` with relative module names should now work correctly with `hy -m`, as well as `hy2py`'s recursive mode. +* `hy.models.Symbol` no longer allows constructing a symbol beginning + with `#`. New Features ------------------------------ diff --git a/hy/reader/hy_reader.py b/hy/reader/hy_reader.py index 016b94e50..923b820e2 100644 --- a/hy/reader/hy_reader.py +++ b/hy/reader/hy_reader.py @@ -98,7 +98,7 @@ def err(msg): if reader is None: if ( not ident - or ident[:1] == ":" + or ident[0] in ":#" or any(isnormalizedspace(c) for c in ident) or HyReader.NON_IDENT.intersection(ident) ): diff --git a/tests/test_models.py b/tests/test_models.py index c000e8bd1..9ad851545 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -28,7 +28,8 @@ def test_symbol_or_keyword(): for x in ("foo", "foo-bar", "foo_bar", "✈é😂⁂"): assert str(Symbol(x)) == x assert Keyword(x).name == x - for x in ("", ":foo", "5"): + for x in ("", ":foo", "5", "#foo"): + # https://github.com/hylang/hy/issues/2383 with pytest.raises(ValueError): Symbol(x) assert Keyword(x).name == x