From 167560d7ddd8fcbb71b3ef8ec42e3affc898c3ff Mon Sep 17 00:00:00 2001 From: "Johan B.W. de Vries" Date: Wed, 15 Nov 2023 12:06:25 +0100 Subject: [PATCH] Replaced pylint with ruff --- Makefile | 2 +- phasm/compiler.py | 2 +- phasm/ourlang.py | 5 ----- phasm/parser.py | 8 ++++---- phasm/runtime.py | 4 +--- phasm/type3/constraints.py | 2 -- phasm/type3/constraintsgenerator.py | 4 ++-- phasm/type3/entry.py | 2 +- requirements.txt | 2 +- tests/integration/helpers.py | 1 - 10 files changed, 11 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index 20dd290..03d4987 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,7 @@ test: venv/.done $(subst .json,.py,$(subst /generator_,/test_generated_,$(wildca venv/bin/pytest tests $(TEST_FLAGS) lint: venv/.done - venv/bin/pylint phasm + venv/bin/ruff check phasm tests/integration/helpers.py tests/integration/runners.py typecheck: venv/.done venv/bin/mypy --strict phasm tests/integration/helpers.py tests/integration/runners.py diff --git a/phasm/compiler.py b/phasm/compiler.py index faed2e7..dc23974 100644 --- a/phasm/compiler.py +++ b/phasm/compiler.py @@ -1,7 +1,7 @@ """ This module contains the code to convert parsed Ourlang into WebAssembly code """ -from typing import List, Optional, Union +from typing import List, Optional import struct diff --git a/phasm/ourlang.py b/phasm/ourlang.py index d602051..c3b0942 100644 --- a/phasm/ourlang.py +++ b/phasm/ourlang.py @@ -5,11 +5,6 @@ from typing import Dict, Iterable, List, Optional, Union import enum -from typing_extensions import Final - -WEBASSEMBLY_BUILTIN_FLOAT_OPS: Final = ('abs', 'sqrt', 'ceil', 'floor', 'trunc', 'nearest', ) -WEBASSEMBLY_BUILTIN_BYTES_OPS: Final = ('len', ) - from .type3 import types as type3types from .type3.types import Type3, Type3OrPlaceholder, PlaceholderForType, StructType3 diff --git a/phasm/parser.py b/phasm/parser.py index 0ce4a91..b12e3f2 100644 --- a/phasm/parser.py +++ b/phasm/parser.py @@ -1,7 +1,7 @@ """ Parses the source code from the plain text into a syntax tree """ -from typing import Any, Dict, List, NoReturn, Union +from typing import Any, Dict, NoReturn, Union import ast @@ -16,7 +16,7 @@ from .ourlang import ( Expression, BinaryOp, - ConstantPrimitive, ConstantMemoryStored, + ConstantPrimitive, ConstantBytes, ConstantTuple, ConstantStruct, TupleInstantiation, @@ -219,7 +219,7 @@ class OurVisitor: if not isinstance(stmt.target, ast.Name): raise NotImplementedError('Class with default values') - if not stmt.value is None: + if stmt.value is not None: raise NotImplementedError('Class with default values') if stmt.simple != 1: @@ -591,7 +591,7 @@ class OurVisitor: if not isinstance(node.func.ctx, ast.Load): _raise_static_error(node.func, 'Must be load context') - if not node.func.id in module.struct_definitions: + if node.func.id not in module.struct_definitions: _raise_static_error(node.func, 'Undefined struct') if node.keywords: diff --git a/phasm/runtime.py b/phasm/runtime.py index 3db1b69..e15c1ca 100644 --- a/phasm/runtime.py +++ b/phasm/runtime.py @@ -1,5 +1,3 @@ -from typing import Union - from .type3 import types as type3types def calculate_alloc_size(typ: type3types.Type3, is_member: bool = False) -> int: @@ -49,7 +47,7 @@ def calculate_alloc_size(typ: type3types.Type3, is_member: bool = False) -> int: assert not isinstance(arg, type3types.IntType3) if isinstance(arg, type3types.PlaceholderForType): - assert not arg.resolve_as is None + assert arg.resolve_as is not None arg = arg.resolve_as size += calculate_alloc_size(arg, is_member=True) diff --git a/phasm/type3/constraints.py b/phasm/type3/constraints.py index 449619a..31814e3 100644 --- a/phasm/type3/constraints.py +++ b/phasm/type3/constraints.py @@ -103,7 +103,6 @@ class SameTypeConstraint(ConstraintBase): def check(self) -> CheckResult: known_types: List[types.Type3] = [] placeholders = [] - do_applied_placeholder_check: bool = False for typ in self.type_list: if isinstance(typ, types.IntType3): known_types.append(typ) @@ -115,7 +114,6 @@ class SameTypeConstraint(ConstraintBase): if isinstance(typ, types.AppliedType3): known_types.append(typ) - do_applied_placeholder_check = True continue if isinstance(typ, types.PlaceholderForType): diff --git a/phasm/type3/constraintsgenerator.py b/phasm/type3/constraintsgenerator.py index 9f4fe9f..ea83ebb 100644 --- a/phasm/type3/constraintsgenerator.py +++ b/phasm/type3/constraintsgenerator.py @@ -138,7 +138,7 @@ def expression(ctx: Context, inp: ourlang.Expression) -> ConstraintGenerator: yield SameTypeConstraint( inp.type3, type3types.AppliedType3(type3types.tuple, r_type), - comment=f'The type of a tuple is a combination of its members' + comment='The type of a tuple is a combination of its members' ) return @@ -178,7 +178,7 @@ def statement_if(ctx: Context, fun: ourlang.Function, inp: ourlang.StatementIf) yield from expression(ctx, inp.test) yield SameTypeConstraint(inp.test.type3, type3types.bool_, - comment=f'Must pass a boolean expression to if') + comment='Must pass a boolean expression to if') for stmt in inp.statements: yield from statement(ctx, fun, stmt) diff --git a/phasm/type3/entry.py b/phasm/type3/entry.py index dfeb06e..66f9a5b 100644 --- a/phasm/type3/entry.py +++ b/phasm/type3/entry.py @@ -1,7 +1,7 @@ """ Entry point to the type3 system """ -from typing import Any, Dict, List, Set +from typing import Dict, List from .. import codestyle from .. import ourlang diff --git a/requirements.txt b/requirements.txt index 64dce30..f797665 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,10 +1,10 @@ mypy==0.991 pygments==2.12.0 -pylint==2.15.9 pytest==7.2.0 pytest-integration==0.2.2 pywasm==1.0.7 pywasm3==0.5.0 +ruff==0.1.5 wasmer==1.1.0 wasmer_compiler_cranelift==1.1.0 wasmtime==3.0.0 diff --git a/tests/integration/helpers.py b/tests/integration/helpers.py index b96cedd..ab672ef 100644 --- a/tests/integration/helpers.py +++ b/tests/integration/helpers.py @@ -195,7 +195,6 @@ def _allocate_memory_stored_value( val_el_typ = val_typ.args[0] assert not isinstance(val_el_typ, type3types.PlaceholderForType) - val_el_alloc_size = calculate_alloc_size(val_el_typ) tuple_len_obj = val_typ.args[1] assert isinstance(tuple_len_obj, type3types.IntType3)