Change KEYWORD_PREFIX to HyKeyword.PREFIX
This commit is contained in:
parent
ace125ee9b
commit
bebcbbeba6
@ -33,7 +33,7 @@
|
|||||||
(import [StringIO [StringIO]])
|
(import [StringIO [StringIO]])
|
||||||
(import [io [StringIO]]))
|
(import [io [StringIO]]))
|
||||||
(import [hy._compat [long-type]]) ; long for python2, int for python3
|
(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.lex [LexException PrematureEndOfInput tokenize]])
|
||||||
(import [hy.compiler [HyASTCompiler]])
|
(import [hy.compiler [HyASTCompiler]])
|
||||||
|
|
||||||
@ -456,7 +456,7 @@
|
|||||||
(defn keyword [value]
|
(defn keyword [value]
|
||||||
"Create a keyword from the given value. Strings numbers and even objects
|
"Create a keyword from the given value. Strings numbers and even objects
|
||||||
with the __name__ magic will work"
|
with the __name__ magic will work"
|
||||||
(if (and (string? value) (value.startswith *keyword-prefix*))
|
(if (and (string? value) (value.startswith HyKeyword.PREFIX))
|
||||||
(hyify value)
|
(hyify value)
|
||||||
(if (string? value)
|
(if (string? value)
|
||||||
(HyKeyword (+ ":" (hyify value)))
|
(HyKeyword (+ ":" (hyify value)))
|
||||||
@ -467,7 +467,7 @@
|
|||||||
(defn name [value]
|
(defn name [value]
|
||||||
"Convert the given value to a string. Keyword special character will be stripped.
|
"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"
|
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))
|
(hyify (cut value 2))
|
||||||
(if (string? value)
|
(if (string? value)
|
||||||
(hyify value)
|
(hyify value)
|
||||||
|
@ -96,17 +96,16 @@ _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")
|
||||||
|
|
||||||
|
|
||||||
KEYWORD_PREFIX = "\uFDD0"
|
|
||||||
|
|
||||||
|
|
||||||
class HyKeyword(HyObject, str_type):
|
class HyKeyword(HyObject, str_type):
|
||||||
"""Generic Hy Keyword object. It's either a ``str`` or a ``unicode``,
|
"""Generic Hy Keyword object. It's either a ``str`` or a ``unicode``,
|
||||||
depending on the Python version.
|
depending on the Python version.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
PREFIX = "\uFDD0"
|
||||||
|
|
||||||
def __new__(cls, value):
|
def __new__(cls, value):
|
||||||
if not value.startswith(KEYWORD_PREFIX):
|
if not value.startswith(cls.PREFIX):
|
||||||
value = KEYWORD_PREFIX + value
|
value = cls.PREFIX + value
|
||||||
|
|
||||||
obj = str_type.__new__(cls, value)
|
obj = str_type.__new__(cls, value)
|
||||||
return obj
|
return obj
|
||||||
|
Loading…
x
Reference in New Issue
Block a user