From 38fdcc2114e12a96a8fa09097fa856e20cdd151c Mon Sep 17 00:00:00 2001 From: Kodi Arfer Date: Mon, 23 Apr 2018 10:52:22 -0700 Subject: [PATCH] Don't let HySymbol inherit from HyString --- NEWS.rst | 1 + docs/language/internals.rst | 16 ++++++++-------- hy/compiler.py | 2 +- hy/models.py | 8 ++++---- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/NEWS.rst b/NEWS.rst index 743835a..5b2d54c 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -33,6 +33,7 @@ Other Breaking Changes * `hy-repr` uses registered functions instead of methods * `HyKeyword` no longer inherits from the string type and has been made into its own object type. +* `HySymbol` no longer inherits from `HyString`. * `(except)` is no longer allowed. Use `(except [])` instead. * `(import [foo])` is no longer allowed. Use `(import foo)` instead. diff --git a/docs/language/internals.rst b/docs/language/internals.rst index 5023f7b..5c3cb09 100644 --- a/docs/language/internals.rst +++ b/docs/language/internals.rst @@ -119,13 +119,12 @@ the following order: HyString ~~~~~~~~ -``hy.models.HyString`` is the base class of string-equivalent Hy -models. It also represents string literals (including bracket strings), which -compile down to unicode string literals in Python. ``HyStrings`` inherit -unicode objects in Python 2, and string objects in Python 3 (and are -therefore not encoding-dependent). +``hy.models.HyString`` represents string literals (including bracket strings), +which compile down to unicode string literals in Python. ``HyStrings`` inherit +unicode objects in Python 2, and string objects in Python 3 (and are therefore +not encoding-dependent). -``HyString`` based models are immutable. +``HyString``\s are immutable. Hy literal strings can span multiple lines, and are considered by the parser as a single unit, respecting the Python escapes for unicode @@ -163,8 +162,9 @@ valid numeric python literals will be turned into their Hy counterpart. HySymbol ~~~~~~~~ -``hy.models.HySymbol`` is the model used to represent symbols -in the Hy language. It inherits :ref:`HyString`. +``hy.models.HySymbol`` is the model used to represent symbols in the Hy +language. Like ``HyString``, it inherits from ``str`` (or ``unicode`` on Python +2). Symbols are :ref:`mangled ` when they are compiled to Python variable names. diff --git a/hy/compiler.py b/hy/compiler.py index 70127df..b4fbda6 100755 --- a/hy/compiler.py +++ b/hy/compiler.py @@ -1298,7 +1298,7 @@ class HyASTCompiler(object): "Can't assign to a callable: `%s'" % str_name) if (result.temp_variables - and isinstance(name, HyString) + and isinstance(name, HySymbol) and '.' not in name): result.rename(name) # Throw away .expr to ensure that (setv ...) returns None. diff --git a/hy/models.py b/hy/models.py index 690025f..d9991f2 100644 --- a/hy/models.py +++ b/hy/models.py @@ -109,13 +109,13 @@ class HyBytes(HyObject, bytes_type): _wrappers[bytes_type] = HyBytes -class HySymbol(HyString): +class HySymbol(HyObject, str_type): """ - Hy Symbol. Basically a String. + Hy Symbol. Basically a string. """ - def __init__(self, string): - self += string + def __new__(cls, s=None): + return super(HySymbol, cls).__new__(cls, s) _wrappers[bool] = lambda x: HySymbol("True") if x else HySymbol("False") _wrappers[type(None)] = lambda foo: HySymbol("None")