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.keyword import HyKeyword
|
||||
|
||||
from hy.util import flatten_literal_list
|
||||
from hy.util import flatten_literal_list, str_type
|
||||
|
||||
from collections import defaultdict
|
||||
import codecs
|
||||
@ -949,10 +949,7 @@ class HyASTCompiler(object):
|
||||
|
||||
@builds(HyKeyword)
|
||||
def compile_keyword(self, keyword):
|
||||
_str_type = str
|
||||
if sys.version_info[0] < 3:
|
||||
_str_type = unicode
|
||||
return ast.Str(s=_str_type(keyword), lineno=keyword.start_line,
|
||||
return ast.Str(s=str_type(keyword), lineno=keyword.start_line,
|
||||
col_offset=keyword.start_column)
|
||||
|
||||
@builds(HyDict)
|
||||
|
@ -20,20 +20,14 @@
|
||||
|
||||
from __future__ import unicode_literals
|
||||
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 HyKeyword(HyObject, _str_type):
|
||||
class HyKeyword(HyObject, str_type):
|
||||
"""Generic Hy Keyword object. It's either a ``str`` or a ``unicode``,
|
||||
depending on the Python version.
|
||||
"""
|
||||
|
||||
def __new__(cls, value):
|
||||
obj = _str_type.__new__(cls, "\uFDD0" + value)
|
||||
obj = str_type.__new__(cls, "\uFDD0" + value)
|
||||
return obj
|
||||
|
@ -19,13 +19,7 @@
|
||||
# DEALINGS IN THE SOFTWARE.
|
||||
|
||||
from hy.models import HyObject
|
||||
import sys
|
||||
|
||||
|
||||
if sys.version_info[0] >= 3:
|
||||
str_type = str
|
||||
else:
|
||||
str_type = unicode
|
||||
from hy.util import 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
|
||||
# DEALINGS IN THE SOFTWARE.
|
||||
|
||||
import sys
|
||||
|
||||
|
||||
if sys.version_info[0] >= 3:
|
||||
str_type = str
|
||||
else:
|
||||
str_type = unicode
|
||||
|
||||
|
||||
def flatten_literal_list(entry):
|
||||
for e in entry:
|
||||
|
Loading…
x
Reference in New Issue
Block a user