Int conversion to long in py2.x
Updated to current master Droped HyInt/HyLong commit
This commit is contained in:
parent
312d4816ce
commit
f61d702788
@ -37,7 +37,7 @@ from hy.models.list import HyList
|
|||||||
from hy.models.dict import HyDict
|
from hy.models.dict import HyDict
|
||||||
|
|
||||||
from hy.macros import require, macroexpand
|
from hy.macros import require, macroexpand
|
||||||
from hy._compat import str_type
|
from hy._compat import str_type, long_type
|
||||||
import hy.importer
|
import hy.importer
|
||||||
|
|
||||||
import traceback
|
import traceback
|
||||||
@ -1753,7 +1753,7 @@ class HyASTCompiler(object):
|
|||||||
|
|
||||||
@builds(HyInteger)
|
@builds(HyInteger)
|
||||||
def compile_integer(self, number):
|
def compile_integer(self, number):
|
||||||
return ast.Num(n=int(number),
|
return ast.Num(n=long_type(number),
|
||||||
lineno=number.start_line,
|
lineno=number.start_line,
|
||||||
col_offset=number.start_column)
|
col_offset=number.start_column)
|
||||||
|
|
||||||
|
@ -26,10 +26,10 @@ from hy.models.integer import HyInteger
|
|||||||
from hy.models.float import HyFloat
|
from hy.models.float import HyFloat
|
||||||
from hy.models.complex import HyComplex
|
from hy.models.complex import HyComplex
|
||||||
from hy.models.dict import HyDict
|
from hy.models.dict import HyDict
|
||||||
from hy._compat import str_type
|
from hy._compat import str_type, long_type
|
||||||
|
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
import sys
|
||||||
|
|
||||||
CORE_MACROS = [
|
CORE_MACROS = [
|
||||||
"hy.core.bootstrap",
|
"hy.core.bootstrap",
|
||||||
@ -87,6 +87,9 @@ _wrappers = {
|
|||||||
list: lambda l: HyList(_wrap_value(x) for x in l)
|
list: lambda l: HyList(_wrap_value(x) for x in l)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if sys.version_info[0] < 3: # do not add long on python3
|
||||||
|
_wrappers[long_type] = HyInteger
|
||||||
|
|
||||||
|
|
||||||
def _wrap_value(x):
|
def _wrap_value(x):
|
||||||
"""Wrap `x` into the corresponding Hy type.
|
"""Wrap `x` into the corresponding Hy type.
|
||||||
|
@ -19,14 +19,16 @@
|
|||||||
# DEALINGS IN THE SOFTWARE.
|
# DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
from hy.models import HyObject
|
from hy.models import HyObject
|
||||||
|
from hy._compat import long_type
|
||||||
|
|
||||||
|
|
||||||
class HyInteger(HyObject, int):
|
class HyInteger(HyObject, long_type):
|
||||||
"""
|
"""
|
||||||
Internal represntation of a Hy Integer. May raise a ValueError as if
|
Internal represntation of a Hy Integer. May raise a ValueError as if
|
||||||
int(foo) was caled, given HyInteger(foo).
|
int(foo) was called, given HyInteger(foo). On python 2.x long will
|
||||||
|
be used instead
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __new__(cls, number, *args, **kwargs):
|
def __new__(cls, number, *args, **kwargs):
|
||||||
number = int(number)
|
number = long_type(number)
|
||||||
return super(HyInteger, cls).__new__(cls, number)
|
return super(HyInteger, cls).__new__(cls, number)
|
||||||
|
@ -163,7 +163,7 @@
|
|||||||
(assert-false (instance? Foo2 foo))
|
(assert-false (instance? Foo2 foo))
|
||||||
(assert-true (instance? Foo foo3))
|
(assert-true (instance? Foo foo3))
|
||||||
(assert-true (instance? float 1.0))
|
(assert-true (instance? float 1.0))
|
||||||
(assert-true (instance? int 3))
|
(assert-true (instance? int (int 3)))
|
||||||
(assert-true (instance? str (str "hello"))))
|
(assert-true (instance? str (str "hello"))))
|
||||||
|
|
||||||
(defn test-integer? []
|
(defn test-integer? []
|
||||||
|
@ -132,3 +132,7 @@
|
|||||||
(let [[x 1]]
|
(let [[x 1]]
|
||||||
(^= x 1)
|
(^= x 1)
|
||||||
(assert (= x 0))))
|
(assert (= x 0))))
|
||||||
|
|
||||||
|
(defn overflow-int-to-long []
|
||||||
|
"NATIVE: test if int does not raise an overflow exception"
|
||||||
|
(assert (integer? (+ 1 1000000000000000000000000))))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user