Factor str_type into hy.util
This commit is contained in:
parent
8bc8a4a170
commit
65c08c8c7d
@ -33,7 +33,7 @@ from hy.models.list import HyList
|
|||||||
from hy.models.dict import HyDict
|
from hy.models.dict import HyDict
|
||||||
from hy.models.keyword import HyKeyword
|
from hy.models.keyword import HyKeyword
|
||||||
|
|
||||||
from hy.util import flatten_literal_list
|
from hy.util import flatten_literal_list, str_type
|
||||||
|
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
import codecs
|
import codecs
|
||||||
@ -949,10 +949,7 @@ class HyASTCompiler(object):
|
|||||||
|
|
||||||
@builds(HyKeyword)
|
@builds(HyKeyword)
|
||||||
def compile_keyword(self, keyword):
|
def compile_keyword(self, keyword):
|
||||||
_str_type = str
|
return ast.Str(s=str_type(keyword), lineno=keyword.start_line,
|
||||||
if sys.version_info[0] < 3:
|
|
||||||
_str_type = unicode
|
|
||||||
return ast.Str(s=_str_type(keyword), lineno=keyword.start_line,
|
|
||||||
col_offset=keyword.start_column)
|
col_offset=keyword.start_column)
|
||||||
|
|
||||||
@builds(HyDict)
|
@builds(HyDict)
|
||||||
|
@ -20,20 +20,14 @@
|
|||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
from hy.models import HyObject
|
from hy.models import HyObject
|
||||||
import sys
|
from hy.util import str_type
|
||||||
|
|
||||||
|
|
||||||
if sys.version_info[0] >= 3:
|
class HyKeyword(HyObject, str_type):
|
||||||
_str_type = str
|
|
||||||
else:
|
|
||||||
_str_type = unicode
|
|
||||||
|
|
||||||
|
|
||||||
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.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __new__(cls, value):
|
def __new__(cls, value):
|
||||||
obj = _str_type.__new__(cls, "\uFDD0" + value)
|
obj = str_type.__new__(cls, "\uFDD0" + value)
|
||||||
return obj
|
return obj
|
||||||
|
@ -19,13 +19,7 @@
|
|||||||
# DEALINGS IN THE SOFTWARE.
|
# DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
from hy.models import HyObject
|
from hy.models import HyObject
|
||||||
import sys
|
from hy.util import str_type
|
||||||
|
|
||||||
|
|
||||||
if sys.version_info[0] >= 3:
|
|
||||||
str_type = str
|
|
||||||
else:
|
|
||||||
str_type = unicode
|
|
||||||
|
|
||||||
|
|
||||||
class HyString(HyObject, str_type):
|
class HyString(HyObject, str_type):
|
||||||
|
@ -18,6 +18,14 @@
|
|||||||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
# DEALINGS IN THE SOFTWARE.
|
# DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
if sys.version_info[0] >= 3:
|
||||||
|
str_type = str
|
||||||
|
else:
|
||||||
|
str_type = unicode
|
||||||
|
|
||||||
|
|
||||||
def flatten_literal_list(entry):
|
def flatten_literal_list(entry):
|
||||||
for e in entry:
|
for e in entry:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user