Don't let HySymbol inherit from HyString
This commit is contained in:
parent
210086c7ca
commit
38fdcc2114
1
NEWS.rst
1
NEWS.rst
@ -33,6 +33,7 @@ Other Breaking Changes
|
|||||||
* `hy-repr` uses registered functions instead of methods
|
* `hy-repr` uses registered functions instead of methods
|
||||||
* `HyKeyword` no longer inherits from the string type and has been
|
* `HyKeyword` no longer inherits from the string type and has been
|
||||||
made into its own object type.
|
made into its own object type.
|
||||||
|
* `HySymbol` no longer inherits from `HyString`.
|
||||||
* `(except)` is no longer allowed. Use `(except [])` instead.
|
* `(except)` is no longer allowed. Use `(except [])` instead.
|
||||||
* `(import [foo])` is no longer allowed. Use `(import foo)` instead.
|
* `(import [foo])` is no longer allowed. Use `(import foo)` instead.
|
||||||
|
|
||||||
|
@ -119,13 +119,12 @@ the following order:
|
|||||||
HyString
|
HyString
|
||||||
~~~~~~~~
|
~~~~~~~~
|
||||||
|
|
||||||
``hy.models.HyString`` is the base class of string-equivalent Hy
|
``hy.models.HyString`` represents string literals (including bracket strings),
|
||||||
models. It also represents string literals (including bracket strings), which
|
which compile down to unicode string literals in Python. ``HyStrings`` inherit
|
||||||
compile down to unicode string literals in Python. ``HyStrings`` inherit
|
unicode objects in Python 2, and string objects in Python 3 (and are therefore
|
||||||
unicode objects in Python 2, and string objects in Python 3 (and are
|
not encoding-dependent).
|
||||||
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
|
Hy literal strings can span multiple lines, and are considered by the
|
||||||
parser as a single unit, respecting the Python escapes for unicode
|
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
|
HySymbol
|
||||||
~~~~~~~~
|
~~~~~~~~
|
||||||
|
|
||||||
``hy.models.HySymbol`` is the model used to represent symbols
|
``hy.models.HySymbol`` is the model used to represent symbols in the Hy
|
||||||
in the Hy language. It inherits :ref:`HyString`.
|
language. Like ``HyString``, it inherits from ``str`` (or ``unicode`` on Python
|
||||||
|
2).
|
||||||
|
|
||||||
Symbols are :ref:`mangled <mangling>` when they are compiled
|
Symbols are :ref:`mangled <mangling>` when they are compiled
|
||||||
to Python variable names.
|
to Python variable names.
|
||||||
|
@ -1298,7 +1298,7 @@ class HyASTCompiler(object):
|
|||||||
"Can't assign to a callable: `%s'" % str_name)
|
"Can't assign to a callable: `%s'" % str_name)
|
||||||
|
|
||||||
if (result.temp_variables
|
if (result.temp_variables
|
||||||
and isinstance(name, HyString)
|
and isinstance(name, HySymbol)
|
||||||
and '.' not in name):
|
and '.' not in name):
|
||||||
result.rename(name)
|
result.rename(name)
|
||||||
# Throw away .expr to ensure that (setv ...) returns None.
|
# Throw away .expr to ensure that (setv ...) returns None.
|
||||||
|
@ -109,13 +109,13 @@ class HyBytes(HyObject, bytes_type):
|
|||||||
_wrappers[bytes_type] = HyBytes
|
_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):
|
def __new__(cls, s=None):
|
||||||
self += string
|
return super(HySymbol, cls).__new__(cls, s)
|
||||||
|
|
||||||
_wrappers[bool] = lambda x: HySymbol("True") if x else HySymbol("False")
|
_wrappers[bool] = lambda x: HySymbol("True") if x else HySymbol("False")
|
||||||
_wrappers[type(None)] = lambda foo: HySymbol("None")
|
_wrappers[type(None)] = lambda foo: HySymbol("None")
|
||||||
|
Loading…
Reference in New Issue
Block a user