Don't let HySymbol inherit from HyString

This commit is contained in:
Kodi Arfer 2018-04-23 10:52:22 -07:00
parent 210086c7ca
commit 38fdcc2114
4 changed files with 14 additions and 13 deletions

View File

@ -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.

View File

@ -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 <mangling>` when they are compiled
to Python variable names.

View File

@ -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.

View File

@ -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")