fix: add final decorator to Visitor subclasses
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
|
from typing import final
|
||||||
|
|
||||||
import midas.ast.midas as m
|
import midas.ast.midas as m
|
||||||
|
|
||||||
|
|
||||||
|
@final
|
||||||
class MidasPrinter(
|
class MidasPrinter(
|
||||||
m.Expr.Visitor[str],
|
m.Expr.Visitor[str],
|
||||||
m.Stmt.Visitor[str],
|
m.Stmt.Visitor[str],
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
|
from typing import final
|
||||||
|
|
||||||
import midas.ast.midas as m
|
import midas.ast.midas as m
|
||||||
from midas.ast.printer.base import AstPrinter
|
from midas.ast.printer.base import AstPrinter
|
||||||
|
|
||||||
|
|
||||||
|
@final
|
||||||
class MidasAstPrinter(
|
class MidasAstPrinter(
|
||||||
AstPrinter,
|
AstPrinter,
|
||||||
m.Expr.Visitor[None],
|
m.Expr.Visitor[None],
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
import ast
|
import ast
|
||||||
|
from typing import final
|
||||||
|
|
||||||
import midas.ast.python as p
|
import midas.ast.python as p
|
||||||
from midas.ast.printer.base import AstPrinter
|
from midas.ast.printer.base import AstPrinter
|
||||||
|
|
||||||
|
|
||||||
|
@final
|
||||||
class PythonAstPrinter(
|
class PythonAstPrinter(
|
||||||
AstPrinter,
|
AstPrinter,
|
||||||
p.MidasType.Visitor[None],
|
p.MidasType.Visitor[None],
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Any, Callable, Optional
|
from typing import Any, Callable, Optional, final
|
||||||
|
|
||||||
import midas.ast.midas as m
|
import midas.ast.midas as m
|
||||||
from midas.ast.location import Location
|
from midas.ast.location import Location
|
||||||
@@ -18,6 +18,7 @@ class PartialPredicate(Predicate):
|
|||||||
"""A dictionary of already applied parameters"""
|
"""A dictionary of already applied parameters"""
|
||||||
|
|
||||||
|
|
||||||
|
@final
|
||||||
class Evaluator(m.Expr.Visitor[Any]):
|
class Evaluator(m.Expr.Visitor[Any]):
|
||||||
"""Helper class to evaluate an expression
|
"""Helper class to evaluate an expression
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import logging
|
import logging
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Optional
|
from typing import Optional, final
|
||||||
|
|
||||||
import midas.ast.midas as m
|
import midas.ast.midas as m
|
||||||
from midas.ast.location import Location
|
from midas.ast.location import Location
|
||||||
@@ -30,6 +30,7 @@ from midas.lexer.token import Token, TokenType
|
|||||||
from midas.parser.midas import MidasParser
|
from midas.parser.midas import MidasParser
|
||||||
|
|
||||||
|
|
||||||
|
@final
|
||||||
class MidasTyper(m.Stmt.Visitor[None], m.Expr.Visitor[Type], m.Type.Visitor[Type]):
|
class MidasTyper(m.Stmt.Visitor[None], m.Expr.Visitor[Type], m.Type.Visitor[Type]):
|
||||||
"""A resolver which evaluates Midas type definitions and build a registry"""
|
"""A resolver which evaluates Midas type definitions and build a registry"""
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import ast
|
import ast
|
||||||
import logging
|
import logging
|
||||||
from typing import Any, Optional
|
from typing import Any, Optional, final
|
||||||
|
|
||||||
import midas.ast.python as p
|
import midas.ast.python as p
|
||||||
from midas.ast.location import Location
|
from midas.ast.location import Location
|
||||||
@@ -55,6 +55,7 @@ class UndefinedMethodException(Exception):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@final
|
||||||
class PythonTyper(
|
class PythonTyper(
|
||||||
p.Stmt.Visitor[None],
|
p.Stmt.Visitor[None],
|
||||||
p.Expr.Visitor[Type],
|
p.Expr.Visitor[Type],
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
from typing import final
|
||||||
|
|
||||||
import midas.ast.python as p
|
import midas.ast.python as p
|
||||||
from midas.ast.location import Location
|
from midas.ast.location import Location
|
||||||
from midas.checker.reporter import FileReporter
|
from midas.checker.reporter import FileReporter
|
||||||
@@ -6,6 +8,7 @@ from midas.checker.reporter import FileReporter
|
|||||||
class ResolverError(Exception): ...
|
class ResolverError(Exception): ...
|
||||||
|
|
||||||
|
|
||||||
|
@final
|
||||||
class Resolver(p.Stmt.Visitor[None], p.Expr.Visitor[None]):
|
class Resolver(p.Stmt.Visitor[None], p.Expr.Visitor[None]):
|
||||||
"""A variable assignment and reference resolver
|
"""A variable assignment and reference resolver
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ from __future__ import annotations
|
|||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Generic, Optional, Protocol, TextIO, TypeVar
|
from typing import Generic, Optional, Protocol, TextIO, TypeVar, final
|
||||||
|
|
||||||
import midas.ast.midas as m
|
import midas.ast.midas as m
|
||||||
import midas.ast.python as p
|
import midas.ast.python as p
|
||||||
@@ -121,6 +121,7 @@ class Highlighter(ABC):
|
|||||||
self.openings.setdefault((l + 1, 0), []).append(opening)
|
self.openings.setdefault((l + 1, 0), []).append(opening)
|
||||||
|
|
||||||
|
|
||||||
|
@final
|
||||||
class PythonHighlighter(
|
class PythonHighlighter(
|
||||||
Highlighter,
|
Highlighter,
|
||||||
p.MidasType.Visitor[None],
|
p.MidasType.Visitor[None],
|
||||||
@@ -255,6 +256,7 @@ class PythonHighlighter(
|
|||||||
def visit_raw_stmt(self, stmt: p.RawStmt) -> None: ...
|
def visit_raw_stmt(self, stmt: p.RawStmt) -> None: ...
|
||||||
|
|
||||||
|
|
||||||
|
@final
|
||||||
class MidasHighlighter(
|
class MidasHighlighter(
|
||||||
Highlighter, m.Stmt.Visitor[None], m.Expr.Visitor[None], m.Type.Visitor[None]
|
Highlighter, m.Stmt.Visitor[None], m.Expr.Visitor[None], m.Type.Visitor[None]
|
||||||
):
|
):
|
||||||
@@ -352,6 +354,7 @@ class MidasHighlighter(
|
|||||||
self.wrap(column, "column")
|
self.wrap(column, "column")
|
||||||
|
|
||||||
|
|
||||||
|
@final
|
||||||
class DiagnosticsHighlighter(Highlighter):
|
class DiagnosticsHighlighter(Highlighter):
|
||||||
EXTRA_CSS_PATH: Optional[Path] = Path(__file__).parent / "hl_diagnostic.css"
|
EXTRA_CSS_PATH: Optional[Path] = Path(__file__).parent / "hl_diagnostic.css"
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import ast
|
import ast
|
||||||
from typing import Optional
|
from typing import Optional, final
|
||||||
|
|
||||||
import midas.ast.midas as m
|
import midas.ast.midas as m
|
||||||
from midas.checker.registry import TypesRegistry
|
from midas.checker.registry import TypesRegistry
|
||||||
@@ -39,6 +39,7 @@ COMPARISON_OPERATORS: dict[TokenType, type[ast.cmpop]] = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@final
|
||||||
class ConstraintGenerator(m.Expr.Visitor[ast.expr]):
|
class ConstraintGenerator(m.Expr.Visitor[ast.expr]):
|
||||||
"""Class to generate Python code for constraint expressions"""
|
"""Class to generate Python code for constraint expressions"""
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import logging
|
|||||||
import shutil
|
import shutil
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Optional, assert_never
|
from typing import Optional, assert_never, final
|
||||||
|
|
||||||
import midas.ast.midas as m
|
import midas.ast.midas as m
|
||||||
import midas.ast.python as p
|
import midas.ast.python as p
|
||||||
@@ -47,6 +47,7 @@ class Scope:
|
|||||||
"""A list of aliases defined in the scope, that can be discard afterwards"""
|
"""A list of aliases defined in the scope, that can be discard afterwards"""
|
||||||
|
|
||||||
|
|
||||||
|
@final
|
||||||
class Generator(p.Stmt.Visitor[ast.stmt], p.Expr.Visitor[ast.expr]):
|
class Generator(p.Stmt.Visitor[ast.stmt], p.Expr.Visitor[ast.expr]):
|
||||||
"""
|
"""
|
||||||
A class to translate the custom Python AST back into raw `ast` nodes
|
A class to translate the custom Python AST back into raw `ast` nodes
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from typing import Optional, Sequence
|
from typing import Optional, Sequence, final
|
||||||
|
|
||||||
from midas.ast.midas import (
|
from midas.ast.midas import (
|
||||||
AliasStmt,
|
AliasStmt,
|
||||||
@@ -28,6 +28,7 @@ from midas.ast.midas import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@final
|
||||||
class MidasAstJsonSerializer(
|
class MidasAstJsonSerializer(
|
||||||
Stmt.Visitor[dict], Expr.Visitor[dict], Type.Visitor[dict]
|
Stmt.Visitor[dict], Expr.Visitor[dict], Type.Visitor[dict]
|
||||||
):
|
):
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import ast
|
import ast
|
||||||
from typing import Optional, Sequence, Type
|
from typing import Optional, Sequence, Type, final
|
||||||
|
|
||||||
from midas.ast.python import (
|
from midas.ast.python import (
|
||||||
AssignStmt,
|
AssignStmt,
|
||||||
@@ -78,6 +78,7 @@ boolean_ops: dict[Type[ast.boolop], str] = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@final
|
||||||
class PythonAstJsonSerializer(
|
class PythonAstJsonSerializer(
|
||||||
Stmt.Visitor[dict], Expr.Visitor[dict], MidasType.Visitor[dict]
|
Stmt.Visitor[dict], Expr.Visitor[dict], MidasType.Visitor[dict]
|
||||||
):
|
):
|
||||||
|
|||||||
Reference in New Issue
Block a user