From ef3bad7e03bedc9dd7625b5aac2a46a9b3c12eff Mon Sep 17 00:00:00 2001 From: Kodi Arfer Date: Thu, 13 Apr 2017 16:09:45 -0700 Subject: [PATCH 1/3] Drop support for Python 2.6 --- hy/_compat.py | 1 - hy/compiler.py | 87 ++++++++++++++++---------------------------------- setup.py | 4 --- 3 files changed, 27 insertions(+), 65 deletions(-) diff --git a/hy/_compat.py b/hy/_compat.py index bdad6da..f41836f 100644 --- a/hy/_compat.py +++ b/hy/_compat.py @@ -38,7 +38,6 @@ 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) diff --git a/hy/compiler.py b/hy/compiler.py index 2933533..ca33010 100644 --- a/hy/compiler.py +++ b/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, PY33, PY3, PY34, PY35, raise_empty) from hy.macros import require, macroexpand, sharp_macroexpand import hy.importer @@ -1547,53 +1547,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 +2267,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") diff --git a/setup.py b/setup.py index ce52007..3011c9e 100755 --- a/setup.py +++ b/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", From 5aaa7d92d893ae3527897c9795940c5149c899ba Mon Sep 17 00:00:00 2001 From: Kodi Arfer Date: Thu, 13 Apr 2017 16:13:03 -0700 Subject: [PATCH 2/3] Shorten hy._compat --- hy/_compat.py | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/hy/_compat.py b/hy/_compat.py index f41836f..7878d03 100644 --- a/hy/_compat.py +++ b/hy/_compat.py @@ -43,25 +43,10 @@ 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') From a27d737e1c6273dcb4c377d123392fc1951b3150 Mon Sep 17 00:00:00 2001 From: Kodi Arfer Date: Thu, 13 Apr 2017 16:17:32 -0700 Subject: [PATCH 3/3] Drop support for Pythons 3 older than 3.3 --- NEWS | 1 + hy/_compat.py | 1 - hy/compiler.py | 15 ++++++--------- hy/core/macros.hy | 3 +-- hy/importer.py | 4 ++-- tests/compilers/test_compiler.py | 4 ++-- tests/native_tests/language.hy | 4 ++-- tests/native_tests/py3_only_tests.hy | 1 - 8 files changed, 14 insertions(+), 19 deletions(-) diff --git a/NEWS b/NEWS index d38f1e7..ed448ec 100644 --- a/NEWS +++ b/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 diff --git a/hy/_compat.py b/hy/_compat.py index 7878d03..217bf2e 100644 --- a/hy/_compat.py +++ b/hy/_compat.py @@ -39,7 +39,6 @@ except ImportError: import sys PY3 = sys.version_info[0] >= 3 -PY33 = sys.version_info >= (3, 3) PY34 = sys.version_info >= (3, 4) PY35 = sys.version_info >= (3, 5) diff --git a/hy/compiler.py b/hy/compiler.py index ca33010..130d3f3 100644 --- a/hy/compiler.py +++ b/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, 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)] @@ -2367,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. diff --git a/hy/core/macros.hy b/hy/core/macros.hy index 7f6f4ba..7416753 100644 --- a/hy/core/macros.hy +++ b/hy/core/macros.hy @@ -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. diff --git a/hy/importer.py b/hy/importer.py index bf71169..1db67e3 100644 --- a/hy/importer.py +++ b/hy/importer.py @@ -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) diff --git a/tests/compilers/test_compiler.py b/tests/compilers/test_compiler.py index 8c3fe93..3f1b397 100644 --- a/tests/compilers/test_compiler.py +++ b/tests/compilers/test_compiler.py @@ -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) diff --git a/tests/native_tests/language.hy b/tests/native_tests/language.hy index 7b11edb..704bd5d 100644 --- a/tests/native_tests/language.hy +++ b/tests/native_tests/language.hy @@ -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) diff --git a/tests/native_tests/py3_only_tests.hy b/tests/native_tests/py3_only_tests.hy index 30044b1..6c577b4 100644 --- a/tests/native_tests/py3_only_tests.hy +++ b/tests/native_tests/py3_only_tests.hy @@ -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]])