Change KEYWORD_PREFIX to HyKeyword.PREFIX

This commit is contained in:
Kodi Arfer 2017-02-16 18:06:45 -08:00
parent ace125ee9b
commit bebcbbeba6
2 changed files with 7 additions and 8 deletions

View File

@ -33,7 +33,7 @@
(import [StringIO [StringIO]])
(import [io [StringIO]]))
(import [hy._compat [long-type]]) ; long for python2, int for python3
(import [hy.models [HyCons HySymbol HyKeyword *keyword-prefix*]])
(import [hy.models [HyCons HySymbol HyKeyword]])
(import [hy.lex [LexException PrematureEndOfInput tokenize]])
(import [hy.compiler [HyASTCompiler]])
@ -456,7 +456,7 @@
(defn keyword [value]
"Create a keyword from the given value. Strings numbers and even objects
with the __name__ magic will work"
(if (and (string? value) (value.startswith *keyword-prefix*))
(if (and (string? value) (value.startswith HyKeyword.PREFIX))
(hyify value)
(if (string? value)
(HyKeyword (+ ":" (hyify value)))
@ -467,7 +467,7 @@
(defn name [value]
"Convert the given value to a string. Keyword special character will be stripped.
String will be used as is. Even objects with the __name__ magic will work"
(if (and (string? value) (value.startswith *keyword-prefix*))
(if (and (string? value) (value.startswith HyKeyword.PREFIX))
(hyify (cut value 2))
(if (string? value)
(hyify value)

View File

@ -96,17 +96,16 @@ _wrappers[bool] = lambda x: HySymbol("True") if x else HySymbol("False")
_wrappers[type(None)] = lambda foo: HySymbol("None")
KEYWORD_PREFIX = "\uFDD0"
class HyKeyword(HyObject, str_type):
"""Generic Hy Keyword object. It's either a ``str`` or a ``unicode``,
depending on the Python version.
"""
PREFIX = "\uFDD0"
def __new__(cls, value):
if not value.startswith(KEYWORD_PREFIX):
value = KEYWORD_PREFIX + value
if not value.startswith(cls.PREFIX):
value = cls.PREFIX + value
obj = str_type.__new__(cls, value)
return obj