Merge pull request #1273 from Kodiologist/out-with-the-old
Drop support for untested versions of Python
This commit is contained in:
commit
401a5e109c
1
NEWS
1
NEWS
@ -1,6 +1,7 @@
|
||||
Changes from 0.12.1
|
||||
|
||||
[ Language Changes ]
|
||||
* Pythons 2.6, 3.0, 3.1, and 3.2 are no longer supported
|
||||
* `let` has been removed. Python's scoping rules do not make a proper
|
||||
implementation of it possible. Use `setv` instead.
|
||||
* `lambda` has been removed, but `fn` now does exactly what `lambda` did
|
||||
|
@ -38,31 +38,14 @@ except ImportError:
|
||||
(x >> 24) & 0xff]))
|
||||
import sys
|
||||
|
||||
PY27 = sys.version_info >= (2, 7)
|
||||
PY3 = sys.version_info[0] >= 3
|
||||
PY33 = sys.version_info >= (3, 3)
|
||||
PY34 = sys.version_info >= (3, 4)
|
||||
PY35 = sys.version_info >= (3, 5)
|
||||
|
||||
if PY3:
|
||||
str_type = str
|
||||
else:
|
||||
str_type = unicode # NOQA
|
||||
|
||||
if PY3:
|
||||
bytes_type = bytes
|
||||
else:
|
||||
bytes_type = str
|
||||
|
||||
if PY3:
|
||||
long_type = int
|
||||
else:
|
||||
long_type = long # NOQA
|
||||
|
||||
if PY3:
|
||||
string_types = str,
|
||||
else:
|
||||
string_types = basestring, # NOQA
|
||||
str_type = str if PY3 else unicode # NOQA
|
||||
bytes_type = bytes if PY3 else str # NOQA
|
||||
long_type = int if PY3 else long # NOQA
|
||||
string_types = str if PY3 else basestring # NOQA
|
||||
|
||||
if PY3:
|
||||
exec('def raise_empty(t, *args): raise t(*args) from None')
|
||||
|
100
hy/compiler.py
100
hy/compiler.py
@ -33,7 +33,7 @@ from hy.lex.parser import hy_symbol_mangle
|
||||
|
||||
import hy.macros
|
||||
from hy._compat import (
|
||||
str_type, bytes_type, long_type, PY27, PY33, PY3, PY34, PY35, raise_empty)
|
||||
str_type, bytes_type, long_type, PY3, PY34, PY35, raise_empty)
|
||||
from hy.macros import require, macroexpand, sharp_macroexpand
|
||||
import hy.importer
|
||||
|
||||
@ -861,7 +861,7 @@ class HyASTCompiler(object):
|
||||
|
||||
ret = handler_results
|
||||
|
||||
if PY33:
|
||||
if PY3:
|
||||
# Python 3.3 features a merge of TryExcept+TryFinally into Try.
|
||||
return ret + ast.Try(
|
||||
lineno=expr.start_line,
|
||||
@ -1170,10 +1170,7 @@ class HyASTCompiler(object):
|
||||
@checkargs(max=1)
|
||||
def compile_yield_expression(self, expr):
|
||||
expr.pop(0)
|
||||
if PY33:
|
||||
ret = Result(contains_yield=False)
|
||||
else:
|
||||
ret = Result(contains_yield=True)
|
||||
ret = Result(contains_yield=(not PY3))
|
||||
|
||||
value = None
|
||||
if expr != []:
|
||||
@ -1190,7 +1187,7 @@ class HyASTCompiler(object):
|
||||
@builds("yield_from")
|
||||
@checkargs(max=1)
|
||||
def compile_yield_from_expression(self, expr):
|
||||
if not PY33:
|
||||
if not PY3:
|
||||
raise HyCompileError(
|
||||
"yield-from only supported in python 3.3+!")
|
||||
|
||||
@ -1464,7 +1461,7 @@ class HyASTCompiler(object):
|
||||
optional_vars=thing,
|
||||
body=body.stmts)
|
||||
|
||||
if PY33:
|
||||
if PY3:
|
||||
the_with.items = [ast.withitem(context_expr=ctx.force_expr,
|
||||
optional_vars=thing)]
|
||||
|
||||
@ -1547,53 +1544,36 @@ class HyASTCompiler(object):
|
||||
@builds("set_comp")
|
||||
@checkargs(min=2, max=3)
|
||||
def compile_set_comprehension(self, expr):
|
||||
if PY27:
|
||||
ret = self.compile_list_comprehension(expr)
|
||||
expr = ret.expr
|
||||
ret.expr = ast.SetComp(
|
||||
lineno=expr.lineno,
|
||||
col_offset=expr.col_offset,
|
||||
elt=expr.elt,
|
||||
generators=expr.generators)
|
||||
ret = self.compile_list_comprehension(expr)
|
||||
expr = ret.expr
|
||||
ret.expr = ast.SetComp(
|
||||
lineno=expr.lineno,
|
||||
col_offset=expr.col_offset,
|
||||
elt=expr.elt,
|
||||
generators=expr.generators)
|
||||
|
||||
return ret
|
||||
|
||||
expr[0] = HySymbol("list_comp").replace(expr[0])
|
||||
expr = HyExpression([HySymbol("set"), expr]).replace(expr)
|
||||
return self.compile(expr)
|
||||
return ret
|
||||
|
||||
@builds("dict_comp")
|
||||
@checkargs(min=3, max=4)
|
||||
def compile_dict_comprehension(self, expr):
|
||||
if PY27:
|
||||
expr.pop(0) # dict-comp
|
||||
key = expr.pop(0)
|
||||
value = expr.pop(0)
|
||||
expr.pop(0) # dict-comp
|
||||
key = expr.pop(0)
|
||||
value = expr.pop(0)
|
||||
|
||||
gen_res, gen = self._compile_generator_iterables(expr)
|
||||
gen_res, gen = self._compile_generator_iterables(expr)
|
||||
|
||||
compiled_key = self.compile(key)
|
||||
compiled_value = self.compile(value)
|
||||
ret = compiled_key + compiled_value + gen_res
|
||||
ret += ast.DictComp(
|
||||
lineno=expr.start_line,
|
||||
col_offset=expr.start_column,
|
||||
key=compiled_key.force_expr,
|
||||
value=compiled_value.force_expr,
|
||||
generators=gen)
|
||||
compiled_key = self.compile(key)
|
||||
compiled_value = self.compile(value)
|
||||
ret = compiled_key + compiled_value + gen_res
|
||||
ret += ast.DictComp(
|
||||
lineno=expr.start_line,
|
||||
col_offset=expr.start_column,
|
||||
key=compiled_key.force_expr,
|
||||
value=compiled_value.force_expr,
|
||||
generators=gen)
|
||||
|
||||
return ret
|
||||
|
||||
# In Python 2.6, turn (dict-comp key value [foo]) into
|
||||
# (dict (list-comp (, key value) [foo]))
|
||||
|
||||
expr[0] = HySymbol("list_comp").replace(expr[0])
|
||||
expr[1:3] = [HyExpression(
|
||||
[HySymbol(",")] +
|
||||
expr[1:3]
|
||||
).replace(expr[1])]
|
||||
expr = HyExpression([HySymbol("dict"), expr]).replace(expr)
|
||||
return self.compile(expr)
|
||||
return ret
|
||||
|
||||
@builds("genexpr")
|
||||
def compile_genexpr(self, expr):
|
||||
@ -2284,26 +2264,10 @@ class HyASTCompiler(object):
|
||||
@builds(HySet)
|
||||
def compile_set(self, expression):
|
||||
elts, ret, _ = self._compile_collect(expression)
|
||||
if PY27:
|
||||
ret += ast.Set(elts=elts,
|
||||
ctx=ast.Load(),
|
||||
lineno=expression.start_line,
|
||||
col_offset=expression.start_column)
|
||||
else:
|
||||
ret += ast.Call(func=ast.Name(id='set',
|
||||
ctx=ast.Load(),
|
||||
lineno=expression.start_line,
|
||||
col_offset=expression.start_column),
|
||||
args=[
|
||||
ast.List(elts=elts,
|
||||
ctx=ast.Load(),
|
||||
lineno=expression.start_line,
|
||||
col_offset=expression.start_column)],
|
||||
keywords=[],
|
||||
starargs=None,
|
||||
kwargs=None,
|
||||
lineno=expression.start_line,
|
||||
col_offset=expression.start_column)
|
||||
ret += ast.Set(elts=elts,
|
||||
ctx=ast.Load(),
|
||||
lineno=expression.start_line,
|
||||
col_offset=expression.start_column)
|
||||
return ret
|
||||
|
||||
@builds("fn")
|
||||
@ -2400,7 +2364,7 @@ class HyASTCompiler(object):
|
||||
return ret
|
||||
|
||||
if body.expr:
|
||||
if body.contains_yield and not PY33:
|
||||
if body.contains_yield and not PY3:
|
||||
# Prior to PEP 380 (introduced in Python 3.3)
|
||||
# generators may not have a value in a return
|
||||
# statement.
|
||||
|
@ -26,8 +26,7 @@
|
||||
;;; They are automatically required in every module, except inside hy.core
|
||||
|
||||
|
||||
(import [hy.models [HyList HySymbol]]
|
||||
[hy._compat [PY33 PY34]])
|
||||
(import [hy.models [HyList HySymbol]])
|
||||
|
||||
(defmacro as-> [head name &rest rest]
|
||||
"Expands to sequence of assignments to the provided name, starting with head.
|
||||
|
@ -35,7 +35,7 @@ import ast
|
||||
import os
|
||||
import __future__
|
||||
|
||||
from hy._compat import PY3, PY33, PY34, MAGIC, builtins, long_type, wr_long
|
||||
from hy._compat import PY3, PY34, MAGIC, builtins, long_type, wr_long
|
||||
from hy._compat import string_types
|
||||
|
||||
|
||||
@ -218,7 +218,7 @@ def write_code_as_pyc(fname, code):
|
||||
with builtins.open(cfile, 'wb') as fc:
|
||||
fc.write(MAGIC)
|
||||
wr_long(fc, timestamp)
|
||||
if PY33:
|
||||
if PY3:
|
||||
wr_long(fc, st.st_size)
|
||||
marshal.dump(code, fc)
|
||||
|
||||
|
4
setup.py
4
setup.py
@ -61,9 +61,6 @@ class Install(install):
|
||||
install.run(self)
|
||||
|
||||
install_requires = ['rply>=0.7.0', 'astor>=0.5', 'clint>=0.4']
|
||||
if sys.version_info[:2] < (2, 7):
|
||||
install_requires.append('argparse>=1.2.1')
|
||||
install_requires.append('importlib>=1.0.2')
|
||||
if os.name == 'nt':
|
||||
install_requires.append('pyreadline>=2.1')
|
||||
|
||||
@ -106,7 +103,6 @@ setup(
|
||||
"Programming Language :: Lisp",
|
||||
"Programming Language :: Python",
|
||||
"Programming Language :: Python :: 2",
|
||||
"Programming Language :: Python :: 2.6",
|
||||
"Programming Language :: Python :: 2.7",
|
||||
"Programming Language :: Python :: 3",
|
||||
"Programming Language :: Python :: 3.3",
|
||||
|
@ -24,7 +24,7 @@ import sys
|
||||
|
||||
from hy import compiler
|
||||
from hy.models import HyExpression, HyList, HySymbol, HyInteger
|
||||
from hy._compat import PY33
|
||||
from hy._compat import PY3
|
||||
|
||||
if sys.version_info[0] <= 2 and sys.version_info[1] <= 6:
|
||||
import unittest2 as unittest
|
||||
@ -105,7 +105,7 @@ class HyASTCompilerTest(unittest.TestCase):
|
||||
self.assertIsInstance(body[0], ast.Expr)
|
||||
self.assertIsInstance(body[0].value, ast.Yield)
|
||||
|
||||
if PY33:
|
||||
if PY3:
|
||||
# From 3.3+, the final statement becomes a return value
|
||||
self.assertIsInstance(body[1], ast.Return)
|
||||
self.assertIsInstance(body[1].value, ast.BinOp)
|
||||
|
@ -5,7 +5,7 @@
|
||||
[hy.errors [HyTypeError]])
|
||||
(import sys)
|
||||
|
||||
(import [hy._compat [PY33 PY34 PY35]])
|
||||
(import [hy._compat [PY3 PY34 PY35]])
|
||||
|
||||
(defn test-sys-argv []
|
||||
"NATIVE: test sys.argv"
|
||||
@ -649,7 +649,7 @@
|
||||
(defn test-yield-with-return []
|
||||
"NATIVE: test yield with return"
|
||||
(defn gen [] (yield 3) "goodbye")
|
||||
(if PY33
|
||||
(if PY3
|
||||
(do (setv gg (gen))
|
||||
(assert (= 3 (next gg)))
|
||||
(try (next gg)
|
||||
|
@ -1,7 +1,6 @@
|
||||
;; Tests where the emitted code relies on Python 3.
|
||||
;; Conditionally included in nosetests runs.
|
||||
|
||||
(import [hy._compat [PY33]])
|
||||
(import [hy.errors [HyCompileError]])
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user