From 6e8059392ea2ca46ccf0f96ed19cd67acb8bc6a9 Mon Sep 17 00:00:00 2001 From: Daniel Flook Date: Thu, 10 Oct 2024 13:31:56 +0100 Subject: [PATCH] Sort imports --- corpus_test/__init__.py | 0 corpus_test/generate_report.py | 3 +- corpus_test/generate_results.py | 8 ++--- hypo_test/__init__.py | 0 hypo_test/expressions.py | 18 ++++++++++- hypo_test/folding.py | 6 ++-- hypo_test/module.py | 14 ++++---- hypo_test/patterns.py | 3 +- hypo_test/test_it.py | 22 +++++++------ src/python_minifier/__init__.py | 16 +++++----- src/python_minifier/__init__.pyi | 3 +- src/python_minifier/__main__.py | 2 +- src/python_minifier/expression_printer.py | 6 ++-- src/python_minifier/f_string.py | 6 ++-- src/python_minifier/module_printer.py | 3 +- src/python_minifier/rename/__init__.py | 2 +- src/python_minifier/rename/bind_names.py | 2 +- src/python_minifier/rename/resolve_names.py | 2 +- src/python_minifier/rename/util.py | 3 +- src/python_minifier/token_printer.py | 1 + .../transforms/constant_folding.py | 4 ++- .../transforms/remove_annotations.py | 3 +- .../transforms/remove_debug.py | 3 +- .../transforms/remove_exception_brackets.py | 3 +- .../transforms/remove_explicit_return_none.py | 3 +- .../transforms/remove_object_base.py | 3 +- src/python_minifier/util.py | 1 + test/test_assignment_expressions.py | 3 ++ test/test_await_fstring.py | 3 ++ test/test_bind_names_python2.py | 1 + test/test_bind_names_python312.py | 1 + test/test_bind_names_python313.py | 1 + test/test_bind_names_python33.py | 1 + test/test_combine_imports.py | 7 ++-- test/test_comprehension_rename.py | 1 + test/test_decorator_expressions.py | 3 ++ test/test_dict_expansion.py | 3 ++ test/test_folding.py | 4 +-- test/test_generic_types.py | 3 ++ test/test_hoist_literals.py | 11 ++++++- test/test_is_ast_node.py | 2 ++ test/test_iterable_unpacking.py | 3 ++ test/test_match.py | 3 ++ test/test_match_rename.py | 32 +++++++++++-------- test/test_name_generator.py | 1 + test/test_nonlocal.py | 1 + test/test_posargs.py | 3 ++ test/test_remove_annotations.py | 7 ++-- test/test_remove_assert.py | 6 ++-- test/test_remove_debug.py | 2 +- test/test_remove_exception_brackets.py | 2 +- test/test_remove_literal_statements.py | 5 +-- test/test_remove_object.py | 5 +-- test/test_remove_pass.py | 6 ++-- test/test_rename_builtins.py | 8 ++--- test/test_rename_locals.py | 5 +-- test/test_slice.py | 1 + test/test_type_param_defaults.py | 2 ++ typing_test/test_badtyping.py | 1 + typing_test/test_typing.py | 3 +- xtest/test_unparse_env.py | 8 +++-- 61 files changed, 191 insertions(+), 97 deletions(-) create mode 100644 corpus_test/__init__.py create mode 100644 hypo_test/__init__.py diff --git a/corpus_test/__init__.py b/corpus_test/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/corpus_test/generate_report.py b/corpus_test/generate_report.py index ecb13cc6..7fe22d2f 100644 --- a/corpus_test/generate_report.py +++ b/corpus_test/generate_report.py @@ -1,10 +1,11 @@ import argparse import os import sys + from dataclasses import dataclass, field from typing import Iterable -from result import Result, ResultReader +from .result import Result, ResultReader ENHANCED_REPORT = os.environ.get('ENHANCED_REPORT', True) diff --git a/corpus_test/generate_results.py b/corpus_test/generate_results.py index e7c52c92..21293dcd 100644 --- a/corpus_test/generate_results.py +++ b/corpus_test/generate_results.py @@ -1,16 +1,14 @@ import argparse import datetime import gzip +import logging import os import sys import time - -import logging - - import python_minifier -from result import Result, ResultWriter + +from .result import Result, ResultWriter try: RE = RecursionError diff --git a/hypo_test/__init__.py b/hypo_test/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/hypo_test/expressions.py b/hypo_test/expressions.py index d6d9a190..fed45b8e 100644 --- a/hypo_test/expressions.py +++ b/hypo_test/expressions.py @@ -5,7 +5,23 @@ import unicodedata from hypothesis import assume -from hypothesis.strategies import integers, lists, binary, sampled_from, recursive, dictionaries, booleans, SearchStrategy, text, composite, one_of, floats, complex_numbers, characters, none +from hypothesis.strategies import ( + SearchStrategy, + binary, + booleans, + characters, + complex_numbers, + composite, + dictionaries, + floats, + integers, + lists, + none, + one_of, + recursive, + sampled_from, + text +) comparison_operators = sampled_from([ ast.Eq(), diff --git a/hypo_test/folding.py b/hypo_test/folding.py index 5900be8a..e881a719 100644 --- a/hypo_test/folding.py +++ b/hypo_test/folding.py @@ -1,8 +1,8 @@ -from hypothesis import assume -from hypothesis.strategies import integers, lists, binary, sampled_from, recursive, dictionaries, booleans, SearchStrategy, text, composite, one_of, floats, complex_numbers, characters, none import ast -from expressions import NameConstant, Num +from hypothesis.strategies import SearchStrategy, composite, lists, recursive, sampled_from + +from .expressions import NameConstant, Num leaves = NameConstant() | Num() diff --git a/hypo_test/module.py b/hypo_test/module.py index 50eabfae..d362da35 100644 --- a/hypo_test/module.py +++ b/hypo_test/module.py @@ -1,10 +1,10 @@ import ast from hypothesis import assume -from hypothesis.strategies import integers, lists, sampled_from, recursive, none, booleans, SearchStrategy, composite, one_of +from hypothesis.strategies import SearchStrategy, booleans, composite, integers, lists, none, one_of, recursive, sampled_from + +from .expressions import Name, arguments, expression, name -from hypo_test.expressions import Name, expression, name -from expressions import arguments @composite def Assign(draw) -> ast.Assign: @@ -193,7 +193,7 @@ def FunctionDef(draw, statements) -> ast.FunctionDef: args = draw(arguments()) body = draw(lists(statements, min_size=1, max_size=3)) decorator_list = draw(lists(Name(), min_size=0, max_size=2)) - type_params = draw(none() | lists(one_of(TypeVar(), TypeVarTuple(), ParamSpec()), min_size=0, max_size=3)) + type_params = draw(lists(one_of(TypeVar(), TypeVarTuple(), ParamSpec()), min_size=0, max_size=3)) returns = draw(none() | expression()) return ast.FunctionDef(n, args, body, decorator_list, returns, type_params=type_params) @@ -203,7 +203,7 @@ def AsyncFunctionDef(draw, statements) -> ast.AsyncFunctionDef: args = draw(arguments()) body = draw(lists(statements, min_size=1, max_size=3)) decorator_list = draw(lists(Name(), min_size=0, max_size=2)) - type_params = draw(none() | lists(one_of(TypeVar(), TypeVarTuple(), ParamSpec()), min_size=0, max_size=3)) + type_params = draw(lists(one_of(TypeVar(), TypeVarTuple(), ParamSpec()), min_size=0, max_size=3)) returns = draw(none() | expression()) return ast.AsyncFunctionDef(n, args, body, decorator_list, returns, type_params=type_params) @@ -230,7 +230,7 @@ def ClassDef(draw, statements) -> ast.ClassDef: keywords=keywords, body=body, decorator_list=decorator_list, - type_params=draw(none() | lists(one_of(TypeVar(), TypeVarTuple(), ParamSpec()), min_size=0, max_size=3)) + type_params=draw(lists(one_of(TypeVar(), TypeVarTuple(), ParamSpec()), min_size=0, max_size=3)) ) if hasattr(ast, 'Print'): @@ -286,7 +286,7 @@ def suite() -> SearchStrategy: ClassDef(statements), Try(statements) ), - max_leaves=150 + max_leaves=100 ) @composite diff --git a/hypo_test/patterns.py b/hypo_test/patterns.py index c1b8f6dc..216bed10 100644 --- a/hypo_test/patterns.py +++ b/hypo_test/patterns.py @@ -3,7 +3,8 @@ import string from hypothesis import assume -from hypothesis.strategies import lists, sampled_from, recursive, text, composite, one_of, none, booleans, integers +from hypothesis.strategies import booleans, composite, integers, lists, none, one_of, recursive, sampled_from, text + @composite def name(draw): diff --git a/hypo_test/test_it.py b/hypo_test/test_it.py index 9327f4b9..9b4a46bb 100644 --- a/hypo_test/test_it.py +++ b/hypo_test/test_it.py @@ -1,19 +1,21 @@ import ast from datetime import timedelta -from hypothesis import given, settings, Verbosity, note, HealthCheck -from folding import FoldableExpression -from patterns import Pattern -from python_minifier import ModulePrinter +from hypothesis import HealthCheck, Verbosity, given, note, settings + from python_minifier.ast_compare import compare_ast from python_minifier.ast_printer import print_ast from python_minifier.expression_printer import ExpressionPrinter -from expressions import Expression -from module import Module, TypeAlias +from python_minifier.module_printer import ModulePrinter from python_minifier.rename.mapper import add_parent from python_minifier.transforms.constant_folding import FoldConstants +from .expressions import Expression +from .folding import FoldableExpression +from .module import Module, TypeAlias +from .patterns import Pattern + @given(node=Expression()) @settings(report_multiple_bugs=False, deadline=timedelta(seconds=1), max_examples=100, suppress_health_check=[HealthCheck.too_slow]) #verbosity=Verbosity.verbose @@ -28,7 +30,7 @@ def test_expression(node): @given(node=Module()) -@settings(report_multiple_bugs=False, deadline=timedelta(seconds=1), max_examples=100, suppress_health_check=[HealthCheck.too_slow]) #verbosity=Verbosity.verbose +@settings(report_multiple_bugs=False, deadline=timedelta(seconds=1), max_examples=100, suppress_health_check=[HealthCheck.too_slow], verbosity=Verbosity.verbose) def test_module(node): assert isinstance(node, ast.Module) @@ -61,7 +63,7 @@ def test_pattern(node): compare_ast(module, ast.parse(code, 'test_pattern')) @given(node=FoldableExpression()) -@settings(report_multiple_bugs=False, deadline=timedelta(seconds=1), max_examples=100000, suppress_health_check=[HealthCheck.too_slow]) #verbosity=Verbosity.verbose +@settings(report_multiple_bugs=False, deadline=timedelta(seconds=1), max_examples=1000, suppress_health_check=[HealthCheck.too_slow]) #verbosity=Verbosity.verbose def test_folding(node): assert isinstance(node, ast.AST) note(print_ast(node)) @@ -74,7 +76,7 @@ def test_folding(node): constant_folder(node) @given(node=TypeAlias()) -@settings(report_multiple_bugs=False, deadline=timedelta(seconds=2), max_examples=1000, verbosity=Verbosity.verbose) +@settings(report_multiple_bugs=False, deadline=timedelta(seconds=2), max_examples=100, verbosity=Verbosity.verbose) def test_type_alias(node): module = ast.Module( @@ -88,7 +90,7 @@ def test_type_alias(node): compare_ast(module, ast.parse(code, 'test_type_alias')) @given(node=TypeAlias()) -@settings(report_multiple_bugs=False, deadline=timedelta(seconds=2), max_examples=1000, verbosity=Verbosity.verbose) +@settings(report_multiple_bugs=False, deadline=timedelta(seconds=2), max_examples=100, verbosity=Verbosity.verbose) def test_function_type_param(node): module = ast.Module( diff --git a/src/python_minifier/__init__.py b/src/python_minifier/__init__.py index a7ab2b67..39f307c1 100644 --- a/src/python_minifier/__init__.py +++ b/src/python_minifier/__init__.py @@ -4,29 +4,29 @@ """ -import python_minifier.ast_compat as ast import re +import python_minifier.ast_compat as ast + from python_minifier.ast_compare import CompareError, compare_ast from python_minifier.module_printer import ModulePrinter from python_minifier.rename import ( - rename_literals, - bind_names, - resolve_names, - rename, + add_namespace, allow_rename_globals, allow_rename_locals, - add_namespace, + bind_names, + rename, + rename_literals, + resolve_names ) - from python_minifier.transforms.combine_imports import CombineImports from python_minifier.transforms.constant_folding import FoldConstants from python_minifier.transforms.remove_annotations import RemoveAnnotations from python_minifier.transforms.remove_annotations_options import RemoveAnnotationsOptions from python_minifier.transforms.remove_asserts import RemoveAsserts from python_minifier.transforms.remove_debug import RemoveDebug -from python_minifier.transforms.remove_explicit_return_none import RemoveExplicitReturnNone from python_minifier.transforms.remove_exception_brackets import remove_no_arg_exception_call +from python_minifier.transforms.remove_explicit_return_none import RemoveExplicitReturnNone from python_minifier.transforms.remove_literal_statements import RemoveLiteralStatements from python_minifier.transforms.remove_object_base import RemoveObject from python_minifier.transforms.remove_pass import RemovePass diff --git a/src/python_minifier/__init__.pyi b/src/python_minifier/__init__.pyi index a414796d..c44e7370 100644 --- a/src/python_minifier/__init__.pyi +++ b/src/python_minifier/__init__.pyi @@ -1,5 +1,6 @@ import ast -from typing import List, Text, AnyStr, Optional, Any, Union + +from typing import Any, AnyStr, List, Optional, Text, Union from .transforms.remove_annotations_options import RemoveAnnotationsOptions as RemoveAnnotationsOptions diff --git a/src/python_minifier/__main__.py b/src/python_minifier/__main__.py index 056fe5ca..179a4817 100644 --- a/src/python_minifier/__main__.py +++ b/src/python_minifier/__main__.py @@ -14,7 +14,7 @@ except metadata.PackageNotFoundError: version = '0.0.0' else: - from pkg_resources import get_distribution, DistributionNotFound + from pkg_resources import DistributionNotFound, get_distribution try: version = get_distribution('python_minifier').version except DistributionNotFound: diff --git a/src/python_minifier/expression_printer.py b/src/python_minifier/expression_printer.py index 300f399c..394e7201 100644 --- a/src/python_minifier/expression_printer.py +++ b/src/python_minifier/expression_printer.py @@ -1,9 +1,9 @@ -import python_minifier.ast_compat as ast import sys -from python_minifier.util import is_ast_node +import python_minifier.ast_compat as ast -from python_minifier.token_printer import TokenPrinter, Delimiter +from python_minifier.token_printer import Delimiter, TokenPrinter +from python_minifier.util import is_ast_node class ExpressionPrinter(object): diff --git a/src/python_minifier/f_string.py b/src/python_minifier/f_string.py index 332a2546..02bb1a4f 100644 --- a/src/python_minifier/f_string.py +++ b/src/python_minifier/f_string.py @@ -6,13 +6,13 @@ """ -import python_minifier.ast_compat as ast import copy import re +import python_minifier.ast_compat as ast + from python_minifier import UnstableMinification -from python_minifier.ast_compare import CompareError -from python_minifier.ast_compare import compare_ast +from python_minifier.ast_compare import CompareError, compare_ast from python_minifier.expression_printer import ExpressionPrinter from python_minifier.ministring import MiniString from python_minifier.token_printer import TokenTypes diff --git a/src/python_minifier/module_printer.py b/src/python_minifier/module_printer.py index d1a8c6b7..897671f3 100644 --- a/src/python_minifier/module_printer.py +++ b/src/python_minifier/module_printer.py @@ -1,6 +1,7 @@ -import python_minifier.ast_compat as ast import sys +import python_minifier.ast_compat as ast + from .expression_printer import ExpressionPrinter from .token_printer import Delimiter from .util import is_ast_node diff --git a/src/python_minifier/rename/__init__.py b/src/python_minifier/rename/__init__.py index 6d054290..37248864 100644 --- a/src/python_minifier/rename/__init__.py +++ b/src/python_minifier/rename/__init__.py @@ -3,4 +3,4 @@ from python_minifier.rename.rename_literals import rename_literals from python_minifier.rename.renamer import rename from python_minifier.rename.resolve_names import resolve_names -from python_minifier.rename.util import allow_rename_locals, allow_rename_globals +from python_minifier.rename.util import allow_rename_globals, allow_rename_locals diff --git a/src/python_minifier/rename/bind_names.py b/src/python_minifier/rename/bind_names.py index 57597674..e3a6dcd4 100644 --- a/src/python_minifier/rename/bind_names.py +++ b/src/python_minifier/rename/bind_names.py @@ -1,7 +1,7 @@ import python_minifier.ast_compat as ast from python_minifier.rename.binding import NameBinding -from python_minifier.rename.util import arg_rename_in_place, get_global_namespace, get_nonlocal_namespace, builtins +from python_minifier.rename.util import arg_rename_in_place, builtins, get_global_namespace from python_minifier.transforms.suite_transformer import NodeVisitor diff --git a/src/python_minifier/rename/resolve_names.py b/src/python_minifier/rename/resolve_names.py index 104b5366..95a0937a 100644 --- a/src/python_minifier/rename/resolve_names.py +++ b/src/python_minifier/rename/resolve_names.py @@ -1,7 +1,7 @@ import python_minifier.ast_compat as ast from python_minifier.rename.binding import BuiltinBinding, NameBinding -from python_minifier.rename.util import get_global_namespace, get_nonlocal_namespace, builtins +from python_minifier.rename.util import builtins, get_global_namespace, get_nonlocal_namespace from python_minifier.util import is_ast_node diff --git a/src/python_minifier/rename/util.py b/src/python_minifier/rename/util.py index b78735ab..c27f0ad2 100644 --- a/src/python_minifier/rename/util.py +++ b/src/python_minifier/rename/util.py @@ -1,6 +1,7 @@ -import python_minifier.ast_compat as ast import sys +import python_minifier.ast_compat as ast + from python_minifier.util import is_ast_node diff --git a/src/python_minifier/token_printer.py b/src/python_minifier/token_printer.py index e8813fd2..71382c92 100644 --- a/src/python_minifier/token_printer.py +++ b/src/python_minifier/token_printer.py @@ -3,6 +3,7 @@ import re import sys + class TokenTypes(object): NoToken = 0 Identifier = 1 diff --git a/src/python_minifier/transforms/constant_folding.py b/src/python_minifier/transforms/constant_folding.py index bc1a33b5..d6f79ae7 100644 --- a/src/python_minifier/transforms/constant_folding.py +++ b/src/python_minifier/transforms/constant_folding.py @@ -1,12 +1,14 @@ -import python_minifier.ast_compat as ast import math import sys +import python_minifier.ast_compat as ast + from python_minifier.ast_compare import compare_ast from python_minifier.expression_printer import ExpressionPrinter from python_minifier.transforms.suite_transformer import SuiteTransformer from python_minifier.util import is_ast_node + class FoldConstants(SuiteTransformer): """ Fold Constants if it would reduce the size of the source diff --git a/src/python_minifier/transforms/remove_annotations.py b/src/python_minifier/transforms/remove_annotations.py index d96a29a9..ae47bc5b 100644 --- a/src/python_minifier/transforms/remove_annotations.py +++ b/src/python_minifier/transforms/remove_annotations.py @@ -1,6 +1,7 @@ -import python_minifier.ast_compat as ast import sys +import python_minifier.ast_compat as ast + from python_minifier.transforms.remove_annotations_options import RemoveAnnotationsOptions from python_minifier.transforms.suite_transformer import SuiteTransformer diff --git a/src/python_minifier/transforms/remove_debug.py b/src/python_minifier/transforms/remove_debug.py index d744c3aa..3cd3580a 100644 --- a/src/python_minifier/transforms/remove_debug.py +++ b/src/python_minifier/transforms/remove_debug.py @@ -1,6 +1,7 @@ -import python_minifier.ast_compat as ast import sys +import python_minifier.ast_compat as ast + from python_minifier.transforms.suite_transformer import SuiteTransformer from python_minifier.util import is_ast_node diff --git a/src/python_minifier/transforms/remove_exception_brackets.py b/src/python_minifier/transforms/remove_exception_brackets.py index 9f98d787..d34a022e 100644 --- a/src/python_minifier/transforms/remove_exception_brackets.py +++ b/src/python_minifier/transforms/remove_exception_brackets.py @@ -8,9 +8,10 @@ We can't generally know if a name refers to an exception, so we only do this for builtin exceptions """ -import python_minifier.ast_compat as ast import sys +import python_minifier.ast_compat as ast + from python_minifier.rename.binding import BuiltinBinding # These are always exceptions, in every version of python diff --git a/src/python_minifier/transforms/remove_explicit_return_none.py b/src/python_minifier/transforms/remove_explicit_return_none.py index c152ea54..93463971 100644 --- a/src/python_minifier/transforms/remove_explicit_return_none.py +++ b/src/python_minifier/transforms/remove_explicit_return_none.py @@ -1,6 +1,7 @@ -import python_minifier.ast_compat as ast import sys +import python_minifier.ast_compat as ast + from python_minifier.transforms.suite_transformer import SuiteTransformer from python_minifier.util import is_ast_node diff --git a/src/python_minifier/transforms/remove_object_base.py b/src/python_minifier/transforms/remove_object_base.py index 9a34b9c9..395959b1 100644 --- a/src/python_minifier/transforms/remove_object_base.py +++ b/src/python_minifier/transforms/remove_object_base.py @@ -1,6 +1,7 @@ -import python_minifier.ast_compat as ast import sys +import python_minifier.ast_compat as ast + from python_minifier.transforms.suite_transformer import SuiteTransformer diff --git a/src/python_minifier/util.py b/src/python_minifier/util.py index 9e80a73b..d1ea6252 100644 --- a/src/python_minifier/util.py +++ b/src/python_minifier/util.py @@ -1,5 +1,6 @@ import python_minifier.ast_compat as ast + def is_ast_node(node, types): """ Is a node one of the specified node types diff --git a/test/test_assignment_expressions.py b/test/test_assignment_expressions.py index 7f371ec0..c88e0b92 100644 --- a/test/test_assignment_expressions.py +++ b/test/test_assignment_expressions.py @@ -1,9 +1,12 @@ import ast import sys + import pytest + from python_minifier import unparse from python_minifier.ast_compare import compare_ast + def test_pep(): if sys.version_info < (3, 8): pytest.skip('No Assignment expressions in python < 3.8') diff --git a/test/test_await_fstring.py b/test/test_await_fstring.py index f37b0953..c3c52513 100644 --- a/test/test_await_fstring.py +++ b/test/test_await_fstring.py @@ -1,9 +1,12 @@ import ast import sys + import pytest + from python_minifier import unparse from python_minifier.ast_compare import compare_ast + def test_await_fstring(): if sys.version_info < (3, 7): pytest.skip('Await in f-string expressions not allowed in python < 3.7') diff --git a/test/test_bind_names_python2.py b/test/test_bind_names_python2.py index 3c255316..4bf159a4 100644 --- a/test/test_bind_names_python2.py +++ b/test/test_bind_names_python2.py @@ -4,6 +4,7 @@ from helpers import assert_namespace_tree + def test_module_namespace(): if sys.version_info >= (3, 0): pytest.skip('Test is for python 2 only') diff --git a/test/test_bind_names_python312.py b/test/test_bind_names_python312.py index 22302cad..51a91afb 100644 --- a/test/test_bind_names_python312.py +++ b/test/test_bind_names_python312.py @@ -4,6 +4,7 @@ from helpers import assert_namespace_tree + def test_class_typevar_default(): if sys.version_info < (3, 12): pytest.skip('Test is for > python3.12 only') diff --git a/test/test_bind_names_python313.py b/test/test_bind_names_python313.py index 6713cfe4..38178d57 100644 --- a/test/test_bind_names_python313.py +++ b/test/test_bind_names_python313.py @@ -4,6 +4,7 @@ from helpers import assert_namespace_tree + def test_class_typevar_default(): if sys.version_info < (3, 13): pytest.skip('Test is for python3.13 only') diff --git a/test/test_bind_names_python33.py b/test/test_bind_names_python33.py index d0ab6b2b..8a8f3dae 100644 --- a/test/test_bind_names_python33.py +++ b/test/test_bind_names_python33.py @@ -4,6 +4,7 @@ from helpers import assert_namespace_tree + def test_module_namespace(): if sys.version_info < (3, 3) or sys.version_info > (3, 4): pytest.skip('Test is for python3.3 only') diff --git a/test/test_combine_imports.py b/test/test_combine_imports.py index ec8933b9..de28e3e2 100644 --- a/test/test_combine_imports.py +++ b/test/test_combine_imports.py @@ -1,10 +1,11 @@ import ast from helpers import print_namespace -from python_minifier import add_namespace -from python_minifier.rename import bind_names, resolve_names -from python_minifier.transforms.combine_imports import CombineImports + from python_minifier.ast_compare import compare_ast +from python_minifier.rename import add_namespace, bind_names, resolve_names +from python_minifier.transforms.combine_imports import CombineImports + def combine_imports(module): add_namespace(module) diff --git a/test/test_comprehension_rename.py b/test/test_comprehension_rename.py index c5eecb5b..4991424f 100644 --- a/test/test_comprehension_rename.py +++ b/test/test_comprehension_rename.py @@ -6,6 +6,7 @@ from python_minifier import minify from python_minifier.ast_compare import compare_ast + def test_listcomp_regression_2_7(): if sys.version_info >= (3, 0): pytest.skip('ListComp doesn\'t create a new namespace in python < 3.0') diff --git a/test/test_decorator_expressions.py b/test/test_decorator_expressions.py index e5d2d9ea..8df82d1e 100644 --- a/test/test_decorator_expressions.py +++ b/test/test_decorator_expressions.py @@ -1,9 +1,12 @@ import ast import sys + import pytest + from python_minifier import unparse from python_minifier.ast_compare import compare_ast + def test_pep(): if sys.version_info < (3, 9): pytest.skip('Decorator expression not allowed in python <3.9') diff --git a/test/test_dict_expansion.py b/test/test_dict_expansion.py index 44834ea9..884d135b 100644 --- a/test/test_dict_expansion.py +++ b/test/test_dict_expansion.py @@ -1,9 +1,12 @@ import ast import sys + import pytest + from python_minifier import unparse from python_minifier.ast_compare import compare_ast + def test_dict_expanson(): if sys.version_info < (3, 5): pytest.skip('dict expansion not allowed in python < 3.5') diff --git a/test/test_folding.py b/test/test_folding.py index 40b22240..d9e1b644 100644 --- a/test/test_folding.py +++ b/test/test_folding.py @@ -3,9 +3,9 @@ import pytest -from python_minifier import add_namespace -from python_minifier.transforms.constant_folding import FoldConstants from python_minifier.ast_compare import compare_ast +from python_minifier.rename import add_namespace +from python_minifier.transforms.constant_folding import FoldConstants def fold_constants(source): diff --git a/test/test_generic_types.py b/test/test_generic_types.py index 07938798..2fbdd847 100644 --- a/test/test_generic_types.py +++ b/test/test_generic_types.py @@ -1,9 +1,12 @@ import ast import sys + import pytest + from python_minifier import unparse from python_minifier.ast_compare import compare_ast + def test_type_statement(): if sys.version_info < (3, 12): pytest.skip('Improved generic syntax python < 3.12') diff --git a/test/test_hoist_literals.py b/test/test_hoist_literals.py index 10602efa..46c22d18 100644 --- a/test/test_hoist_literals.py +++ b/test/test_hoist_literals.py @@ -6,7 +6,16 @@ from python_minifier import unparse from python_minifier.ast_compare import compare_ast from python_minifier.ast_printer import print_ast -from python_minifier.rename import add_namespace, bind_names, resolve_names, rename, rename_literals, allow_rename_locals, allow_rename_globals +from python_minifier.rename import ( + add_namespace, + allow_rename_globals, + allow_rename_locals, + bind_names, + rename, + rename_literals, + resolve_names +) + def hoist(source): module = ast.parse(source) diff --git a/test/test_is_ast_node.py b/test/test_is_ast_node.py index 25d8b253..f92a54d3 100644 --- a/test/test_is_ast_node.py +++ b/test/test_is_ast_node.py @@ -3,8 +3,10 @@ import pytest import python_minifier.ast_compat as ast + from python_minifier.util import is_ast_node + def test_type_nodes(): assert is_ast_node(ast.Str('a'), ast.Str) diff --git a/test/test_iterable_unpacking.py b/test/test_iterable_unpacking.py index dd95a2b8..b6a87270 100644 --- a/test/test_iterable_unpacking.py +++ b/test/test_iterable_unpacking.py @@ -1,9 +1,12 @@ import ast import sys + import pytest + from python_minifier import unparse from python_minifier.ast_compare import compare_ast + def test_return(): if sys.version_info < (3, 0): pytest.skip('Iterable unpacking in return not allowed in python < 3.0') diff --git a/test/test_match.py b/test/test_match.py index eb783abd..b5f99579 100644 --- a/test/test_match.py +++ b/test/test_match.py @@ -1,9 +1,12 @@ import ast import sys + import pytest + from python_minifier import unparse from python_minifier.ast_compare import compare_ast + def test_pep635_unparse(): if sys.version_info < (3, 10): pytest.skip('Match statement not in python < 3.10') diff --git a/test/test_match_rename.py b/test/test_match_rename.py index dede5343..207fa56e 100644 --- a/test/test_match_rename.py +++ b/test/test_match_rename.py @@ -3,13 +3,19 @@ import pytest -from python_minifier import ( - add_namespace, bind_names, resolve_names, allow_rename_locals, allow_rename_globals, - compare_ast, rename as do_rename, CompareError, unparse, rename_literals +from python_minifier import unparse +from python_minifier.rename import ( + add_namespace, + allow_rename_globals, + allow_rename_locals, + bind_names, + rename, + rename_literals, + resolve_names ) -def rename(source, locals, globals): +def do_rename(source, locals, globals): # This will raise if the source file can't be parsed module = ast.parse(source, 'test_match_rename') add_namespace(module) @@ -20,7 +26,7 @@ def rename(source, locals, globals): allow_rename_globals(module, globals) rename_literals(module) - do_rename(module) + rename(module) return module @@ -63,7 +69,7 @@ def C(): ''' expected_ast = ast.parse(expected) - actual_ast = rename(source, locals=False, globals=True) + actual_ast = do_rename(source, locals=False, globals=True) assert_code(expected_ast, actual_ast) @@ -102,7 +108,7 @@ def func(expensive_rename): ''' expected_ast = ast.parse(expected) - actual_ast = rename(source, locals=True, globals=False) + actual_ast = do_rename(source, locals=True, globals=False) assert_code(expected_ast, actual_ast) @@ -135,7 +141,7 @@ def func(expensive_rename): ''' expected_ast = ast.parse(expected) - actual_ast = rename(source, locals=True, globals=False) + actual_ast = do_rename(source, locals=True, globals=False) assert_code(expected_ast, actual_ast) @@ -173,7 +179,7 @@ def C(expensive_rename): ''' expected_ast = ast.parse(expected) - actual_ast = rename(source, locals=False, globals=True) + actual_ast = do_rename(source, locals=False, globals=True) assert_code(expected_ast, actual_ast) @@ -206,7 +212,7 @@ def func(expensive_rename): ''' expected_ast = ast.parse(expected) - actual_ast = rename(source, locals=True, globals=False) + actual_ast = do_rename(source, locals=True, globals=False) assert_code(expected_ast, actual_ast) @@ -239,7 +245,7 @@ def B(expensive_rename): ''' expected_ast = ast.parse(expected) - actual_ast = rename(source, locals=False, globals=True) + actual_ast = do_rename(source, locals=False, globals=True) assert_code(expected_ast, actual_ast) @@ -296,7 +302,7 @@ class A: pass ''' expected_ast = ast.parse(expected) - actual_ast = rename(source, locals=True, globals=False) + actual_ast = do_rename(source, locals=True, globals=False) assert_code(expected_ast, actual_ast) @@ -351,5 +357,5 @@ class Local: pass ''' expected_ast = ast.parse(expected) - actual_ast = rename(source, locals=False, globals=True) + actual_ast = do_rename(source, locals=False, globals=True) assert_code(expected_ast, actual_ast) diff --git a/test/test_name_generator.py b/test/test_name_generator.py index 6df0621b..658e832a 100644 --- a/test/test_name_generator.py +++ b/test/test_name_generator.py @@ -2,6 +2,7 @@ from python_minifier.rename.name_generator import name_filter + def test_name_generator(): ng = name_filter() diff --git a/test/test_nonlocal.py b/test/test_nonlocal.py index dd6205e0..7a51e408 100644 --- a/test/test_nonlocal.py +++ b/test/test_nonlocal.py @@ -4,6 +4,7 @@ import python_minifier + def test_nonlocal_name(): if sys.version_info < (3, 0): pytest.skip('No nonlocal in python < 3.0') diff --git a/test/test_posargs.py b/test/test_posargs.py index 6dedd0de..3eb81c0d 100644 --- a/test/test_posargs.py +++ b/test/test_posargs.py @@ -1,10 +1,13 @@ import ast import sys + import pytest + from python_minifier import unparse from python_minifier.ast_compare import compare_ast from python_minifier.transforms.remove_posargs import remove_posargs + def test_pep(): if sys.version_info < (3, 8): pytest.skip('No Assignment expressions in python < 3.8') diff --git a/test/test_remove_annotations.py b/test/test_remove_annotations.py index ecc27f80..6cabfee7 100644 --- a/test/test_remove_annotations.py +++ b/test/test_remove_annotations.py @@ -1,10 +1,13 @@ import ast import sys + import pytest -from python_minifier import add_namespace, RemoveAnnotationsOptions -from python_minifier.transforms.remove_annotations import RemoveAnnotations +from python_minifier import RemoveAnnotationsOptions from python_minifier.ast_compare import compare_ast +from python_minifier.rename import add_namespace +from python_minifier.transforms.remove_annotations import RemoveAnnotations + def remove_annotations(source, **kwargs): module = ast.parse(source) diff --git a/test/test_remove_assert.py b/test/test_remove_assert.py index 5a19f199..b7116162 100644 --- a/test/test_remove_assert.py +++ b/test/test_remove_assert.py @@ -1,7 +1,9 @@ import ast -from python_minifier import add_namespace, bind_names, resolve_names -from python_minifier.transforms.remove_asserts import RemoveAsserts + from python_minifier.ast_compare import compare_ast +from python_minifier.rename import add_namespace, bind_names, resolve_names +from python_minifier.transforms.remove_asserts import RemoveAsserts + def remove_asserts(source): module = ast.parse(source, 'remove_asserts') diff --git a/test/test_remove_debug.py b/test/test_remove_debug.py index 34d99570..aa4ce1a7 100644 --- a/test/test_remove_debug.py +++ b/test/test_remove_debug.py @@ -2,8 +2,8 @@ import pytest -from python_minifier import add_namespace, bind_names, resolve_names from python_minifier.ast_compare import compare_ast +from python_minifier.rename import add_namespace, bind_names, resolve_names from python_minifier.transforms.remove_debug import RemoveDebug diff --git a/test/test_remove_exception_brackets.py b/test/test_remove_exception_brackets.py index cff97a5b..b7d3d358 100644 --- a/test/test_remove_exception_brackets.py +++ b/test/test_remove_exception_brackets.py @@ -3,8 +3,8 @@ import pytest -from python_minifier.rename import add_namespace, bind_names, resolve_names from python_minifier.ast_compare import compare_ast +from python_minifier.rename import add_namespace, bind_names, resolve_names from python_minifier.transforms.remove_exception_brackets import remove_no_arg_exception_call diff --git a/test/test_remove_literal_statements.py b/test/test_remove_literal_statements.py index 1268d410..512dca1a 100644 --- a/test/test_remove_literal_statements.py +++ b/test/test_remove_literal_statements.py @@ -1,8 +1,9 @@ import ast -from python_minifier import add_namespace, bind_names, resolve_names -from python_minifier.transforms.remove_literal_statements import RemoveLiteralStatements from python_minifier.ast_compare import compare_ast +from python_minifier.rename import add_namespace, bind_names, resolve_names +from python_minifier.transforms.remove_literal_statements import RemoveLiteralStatements + def remove_literals(source): module = ast.parse(source, 'test_remove_literal_statements') diff --git a/test/test_remove_object.py b/test/test_remove_object.py index d4b45418..ffd74e93 100644 --- a/test/test_remove_object.py +++ b/test/test_remove_object.py @@ -1,9 +1,10 @@ import ast -import pytest import sys -from python_minifier.transforms.remove_object_base import RemoveObject +import pytest + from python_minifier.ast_compare import compare_ast +from python_minifier.transforms.remove_object_base import RemoveObject def test_remove_object_py3(): diff --git a/test/test_remove_pass.py b/test/test_remove_pass.py index e4861497..4838fee1 100644 --- a/test/test_remove_pass.py +++ b/test/test_remove_pass.py @@ -1,7 +1,9 @@ import ast -from python_minifier import add_namespace, bind_names, resolve_names -from python_minifier.transforms.remove_pass import RemovePass + from python_minifier.ast_compare import compare_ast +from python_minifier.rename import add_namespace, bind_names, resolve_names +from python_minifier.transforms.remove_pass import RemovePass + def remove_literals(source): module = ast.parse(source, 'remove_literals') diff --git a/test/test_rename_builtins.py b/test/test_rename_builtins.py index b2857df7..4fb4f92b 100644 --- a/test/test_rename_builtins.py +++ b/test/test_rename_builtins.py @@ -5,12 +5,10 @@ """ import ast -import sys -import pytest - -from python_minifier import add_namespace, bind_names, resolve_names, allow_rename_locals, allow_rename_globals, \ - compare_ast, rename, CompareError, unparse +from python_minifier import unparse +from python_minifier.ast_compare import CompareError, compare_ast +from python_minifier.rename import add_namespace, allow_rename_globals, allow_rename_locals, bind_names, rename, resolve_names def do_rename(source): diff --git a/test/test_rename_locals.py b/test/test_rename_locals.py index 9bfd8469..d7ce3f66 100644 --- a/test/test_rename_locals.py +++ b/test/test_rename_locals.py @@ -9,8 +9,9 @@ import pytest -from python_minifier import add_namespace, bind_names, resolve_names, allow_rename_locals, allow_rename_globals, \ - compare_ast, rename, CompareError, unparse +from python_minifier import unparse +from python_minifier.ast_compare import CompareError, compare_ast +from python_minifier.rename import add_namespace, allow_rename_globals, allow_rename_locals, bind_names, rename, resolve_names def rename_locals(source): diff --git a/test/test_slice.py b/test/test_slice.py index f2f68f3c..445b83ee 100644 --- a/test/test_slice.py +++ b/test/test_slice.py @@ -3,6 +3,7 @@ from python_minifier import unparse from python_minifier.ast_compare import compare_ast + def test_slice(): """AST for slices was changed in 3.9""" diff --git a/test/test_type_param_defaults.py b/test/test_type_param_defaults.py index f5133abe..4498ccac 100644 --- a/test/test_type_param_defaults.py +++ b/test/test_type_param_defaults.py @@ -1,6 +1,8 @@ import ast import sys + import pytest + from python_minifier import unparse from python_minifier.ast_compare import compare_ast diff --git a/typing_test/test_badtyping.py b/typing_test/test_badtyping.py index 45a3263d..130f18b3 100644 --- a/typing_test/test_badtyping.py +++ b/typing_test/test_badtyping.py @@ -4,6 +4,7 @@ from python_minifier import minify + def test_typing() -> None: minify(456, diff --git a/typing_test/test_typing.py b/typing_test/test_typing.py index 3adf3283..bf18496f 100644 --- a/typing_test/test_typing.py +++ b/typing_test/test_typing.py @@ -4,7 +4,8 @@ import ast -from python_minifier import minify, unparse, awslambda, RemoveAnnotationsOptions +from python_minifier import RemoveAnnotationsOptions, awslambda, minify, unparse + def test_typing() -> None: """ This should have good types """ diff --git a/xtest/test_unparse_env.py b/xtest/test_unparse_env.py index b0ef18d0..8dce3369 100644 --- a/xtest/test_unparse_env.py +++ b/xtest/test_unparse_env.py @@ -1,12 +1,14 @@ +import ast import os import sys -import ast -import pytest import warnings -warnings.filterwarnings("ignore") + +import pytest from python_minifier import minify, unparse +warnings.filterwarnings("ignore") + def gather_files(): print('Interpreter version: ', sys.version_info) print('sys.path: ', sys.path)