Remove internal checks for Python 3.5
This commit is contained in:
parent
49c9d8a845
commit
0fe7f42efc
@ -15,7 +15,7 @@ from hy.errors import (HyCompileError, HyTypeError, HyLanguageError,
|
|||||||
from hy.lex import mangle, unmangle, hy_parse, parse_one_thing, LexException
|
from hy.lex import mangle, unmangle, hy_parse, parse_one_thing, LexException
|
||||||
|
|
||||||
from hy._compat import (string_types, str_type, bytes_type, long_type, PY3,
|
from hy._compat import (string_types, str_type, bytes_type, long_type, PY3,
|
||||||
PY35, PY36, reraise)
|
PY36, reraise)
|
||||||
from hy.macros import require, load_macros, macroexpand, tag_macroexpand
|
from hy.macros import require, load_macros, macroexpand, tag_macroexpand
|
||||||
|
|
||||||
import hy.core
|
import hy.core
|
||||||
@ -106,7 +106,7 @@ def ast_str(x, piecewise=False):
|
|||||||
_special_form_compilers = {}
|
_special_form_compilers = {}
|
||||||
_model_compilers = {}
|
_model_compilers = {}
|
||||||
_decoratables = (ast.FunctionDef, ast.ClassDef)
|
_decoratables = (ast.FunctionDef, ast.ClassDef)
|
||||||
if PY35:
|
if PY3:
|
||||||
_decoratables += (ast.AsyncFunctionDef,)
|
_decoratables += (ast.AsyncFunctionDef,)
|
||||||
# _bad_roots are fake special operators, which are used internally
|
# _bad_roots are fake special operators, which are used internally
|
||||||
# by other special forms (e.g., `except` in `try`) but can't be
|
# by other special forms (e.g., `except` in `try`) but can't be
|
||||||
@ -279,7 +279,7 @@ class Result(object):
|
|||||||
var.arg = new_name
|
var.arg = new_name
|
||||||
elif isinstance(var, ast.FunctionDef):
|
elif isinstance(var, ast.FunctionDef):
|
||||||
var.name = new_name
|
var.name = new_name
|
||||||
elif PY35 and isinstance(var, ast.AsyncFunctionDef):
|
elif PY3 and isinstance(var, ast.AsyncFunctionDef):
|
||||||
var.name = new_name
|
var.name = new_name
|
||||||
else:
|
else:
|
||||||
raise TypeError("Don't know how to rename a %s!" % (
|
raise TypeError("Don't know how to rename a %s!" % (
|
||||||
@ -475,7 +475,7 @@ class HyASTCompiler(object):
|
|||||||
exprs_iter = iter(exprs)
|
exprs_iter = iter(exprs)
|
||||||
for expr in exprs_iter:
|
for expr in exprs_iter:
|
||||||
|
|
||||||
if not PY35 and oldpy_unpack and is_unpack("iterable", expr):
|
if not PY3 and oldpy_unpack and is_unpack("iterable", expr):
|
||||||
if oldpy_starargs:
|
if oldpy_starargs:
|
||||||
raise self._syntax_error(expr,
|
raise self._syntax_error(expr,
|
||||||
"Pythons < 3.5 allow only one `unpack-iterable` per call")
|
"Pythons < 3.5 allow only one `unpack-iterable` per call")
|
||||||
@ -485,7 +485,7 @@ class HyASTCompiler(object):
|
|||||||
|
|
||||||
elif is_unpack("mapping", expr):
|
elif is_unpack("mapping", expr):
|
||||||
ret += self.compile(expr[1])
|
ret += self.compile(expr[1])
|
||||||
if PY35:
|
if PY3:
|
||||||
if dict_display:
|
if dict_display:
|
||||||
compiled_exprs.append(None)
|
compiled_exprs.append(None)
|
||||||
compiled_exprs.append(ret.force_expr)
|
compiled_exprs.append(ret.force_expr)
|
||||||
@ -912,7 +912,7 @@ class HyASTCompiler(object):
|
|||||||
ret += self.compile(arg)
|
ret += self.compile(arg)
|
||||||
return ret + asty.Yield(expr, value=ret.force_expr)
|
return ret + asty.Yield(expr, value=ret.force_expr)
|
||||||
|
|
||||||
@special([(PY3, "yield-from"), (PY35, "await")], [FORM])
|
@special([(PY3, "yield-from"), (PY3, "await")], [FORM])
|
||||||
def compile_yield_from_or_await_expression(self, expr, root, arg):
|
def compile_yield_from_or_await_expression(self, expr, root, arg):
|
||||||
ret = Result() + self.compile(arg)
|
ret = Result() + self.compile(arg)
|
||||||
node = asty.YieldFrom if root == "yield-from" else asty.Await
|
node = asty.YieldFrom if root == "yield-from" else asty.Await
|
||||||
@ -991,7 +991,7 @@ class HyASTCompiler(object):
|
|||||||
fn.stmts[-1].decorator_list = decs + fn.stmts[-1].decorator_list
|
fn.stmts[-1].decorator_list = decs + fn.stmts[-1].decorator_list
|
||||||
return ret + fn
|
return ret + fn
|
||||||
|
|
||||||
@special(["with*", (PY35, "with/a*")],
|
@special(["with*", (PY3, "with/a*")],
|
||||||
[brackets(FORM, maybe(FORM)), many(FORM)])
|
[brackets(FORM, maybe(FORM)), many(FORM)])
|
||||||
def compile_with_expression(self, expr, root, args, body):
|
def compile_with_expression(self, expr, root, args, body):
|
||||||
thing, ctx = (None, args[0]) if args[1] is None else args
|
thing, ctx = (None, args[0]) if args[1] is None else args
|
||||||
@ -1348,11 +1348,11 @@ class HyASTCompiler(object):
|
|||||||
"|": ast.BitOr,
|
"|": ast.BitOr,
|
||||||
"^": ast.BitXor,
|
"^": ast.BitXor,
|
||||||
"&": ast.BitAnd}
|
"&": ast.BitAnd}
|
||||||
if PY35:
|
if PY3:
|
||||||
m_ops["@"] = ast.MatMult
|
m_ops["@"] = ast.MatMult
|
||||||
|
|
||||||
@special(["+", "*", "|"], [many(FORM)])
|
@special(["+", "*", "|"], [many(FORM)])
|
||||||
@special(["-", "/", "&", (PY35, "@")], [oneplus(FORM)])
|
@special(["-", "/", "&", (PY3, "@")], [oneplus(FORM)])
|
||||||
@special(["**", "//", "<<", ">>"], [times(2, Inf, FORM)])
|
@special(["**", "//", "<<", ">>"], [times(2, Inf, FORM)])
|
||||||
@special(["%", "^"], [times(2, 2, FORM)])
|
@special(["%", "^"], [times(2, 2, FORM)])
|
||||||
def compile_maths_expression(self, expr, root, args):
|
def compile_maths_expression(self, expr, root, args):
|
||||||
@ -1478,7 +1478,7 @@ class HyASTCompiler(object):
|
|||||||
|
|
||||||
NASYM = some(lambda x: isinstance(x, HySymbol) and x not in (
|
NASYM = some(lambda x: isinstance(x, HySymbol) and x not in (
|
||||||
"&optional", "&rest", "&kwonly", "&kwargs"))
|
"&optional", "&rest", "&kwonly", "&kwargs"))
|
||||||
@special(["fn", "fn*", (PY35, "fn/a")], [
|
@special(["fn", "fn*", (PY3, "fn/a")], [
|
||||||
# The starred version is for internal use (particularly, in the
|
# The starred version is for internal use (particularly, in the
|
||||||
# definition of `defn`). It ensures that a FunctionDef is
|
# definition of `defn`). It ensures that a FunctionDef is
|
||||||
# produced rather than a Lambda.
|
# produced rather than a Lambda.
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
;;;; Hy shadow functions
|
;;;; Hy shadow functions
|
||||||
|
|
||||||
(import operator)
|
(import operator)
|
||||||
(import [hy._compat [PY3 PY35]])
|
(import [hy._compat [PY3]])
|
||||||
|
|
||||||
(require [hy.core.bootstrap [*]])
|
(require [hy.core.bootstrap [*]])
|
||||||
|
|
||||||
@ -60,7 +60,7 @@
|
|||||||
"Shadowed `%` operator takes `x` modulo `y`."
|
"Shadowed `%` operator takes `x` modulo `y`."
|
||||||
(% x y))
|
(% x y))
|
||||||
|
|
||||||
(if PY35
|
(if PY3
|
||||||
(defn @ [a1 &rest a-rest]
|
(defn @ [a1 &rest a-rest]
|
||||||
"Shadowed `@` operator matrix multiples `a1` by each `a-rest`."
|
"Shadowed `@` operator matrix multiples `a1` by each `a-rest`."
|
||||||
(reduce operator.matmul a-rest a1)))
|
(reduce operator.matmul a-rest a1)))
|
||||||
@ -173,5 +173,5 @@
|
|||||||
'and 'or 'not
|
'and 'or 'not
|
||||||
'is 'is-not 'in 'not-in
|
'is 'is-not 'in 'not-in
|
||||||
'get])
|
'get])
|
||||||
(if (not PY35)
|
(if (not PY3)
|
||||||
(.remove EXPORTS '@))
|
(.remove EXPORTS '@))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user