Skip to content

Commit

Permalink
Merge pull request hylang#2454 from Kodiologist/hashsym
Browse files Browse the repository at this point in the history
Forbid `Symbol("#foo")`
  • Loading branch information
Kodiologist authored Jun 10, 2023
2 parents 6bb0ee9 + 9916b7d commit a39e2bd
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
2 changes: 2 additions & 0 deletions NEWS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------------------------
Expand Down
2 changes: 1 addition & 1 deletion hy/reader/hy_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
):
Expand Down
2 changes: 1 addition & 1 deletion tests/macros/test_macro_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 2 additions & 1 deletion tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a39e2bd

Please sign in to comment.