diff --git a/gen/gen.py b/gen/gen.py index 50c9c9d..9ea59ee 100644 --- a/gen/gen.py +++ b/gen/gen.py @@ -1,3 +1,9 @@ +""" +Helper script to generate AST nodes for Midas and Python. + +Takes in simple templates and generates full dataclasses and a visitor interface +""" + import re from pathlib import Path diff --git a/midas/ast/location.py b/midas/ast/location.py index 47fe360..4d1d7bf 100644 --- a/midas/ast/location.py +++ b/midas/ast/location.py @@ -13,6 +13,8 @@ class HasLocation(Protocol): @dataclass(frozen=True, kw_only=True) class Location: + """Information about the location of an AST node""" + lineno: int col_offset: int end_lineno: Optional[int] @@ -29,6 +31,16 @@ class Location: @staticmethod def span(start: Location, end: Location) -> Location: + """Create a new location spanning from one location to another + + Args: + start (Location): the starting location + end (Location): the end location + + Returns: + Location: a new location spanning from the start of `start` + to the end of `end` + """ return Location( lineno=start.lineno, col_offset=start.col_offset, diff --git a/midas/checker/builtins.py b/midas/checker/builtins.py index be6a781..427d414 100644 --- a/midas/checker/builtins.py +++ b/midas/checker/builtins.py @@ -14,12 +14,15 @@ if TYPE_CHECKING: from midas.checker.registry import TypesRegistry -# Hard-coded subtype relationships between builtin types -# Circular dependencies and diamond inheritance MUST be avoided BUILTIN_SUBTYPES: dict[str, set[str]] = { "object": {"float", "list", "dict", "str", "bytes", "tuple"}, "float": {"int"}, } +""" +Hard-coded subtype relationships between builtin types + +Circular dependencies and diamond inheritance MUST be avoided +""" def define_builtins(reg: TypesRegistry): diff --git a/midas/checker/checker.py b/midas/checker/checker.py index c64a282..a305ad1 100644 --- a/midas/checker/checker.py +++ b/midas/checker/checker.py @@ -10,6 +10,11 @@ from midas.utils import TypedAST class TypeChecker: + """Type checking dispatcher + + Contains a typer for Midas and one for Python, as well as the types registry + """ + def __init__(self): self.types: TypesRegistry = TypesRegistry() self.reporter: Reporter = Reporter() diff --git a/midas/checker/diagnostic.py b/midas/checker/diagnostic.py index 233dd74..04a5ce2 100644 --- a/midas/checker/diagnostic.py +++ b/midas/checker/diagnostic.py @@ -14,6 +14,15 @@ class DiagnosticType(StrEnum): @dataclass(frozen=True) class Diagnostic: + """Information about a diagnostic (warning, errors, etc.) + + Holds a location, a diagnostic type and a message. + Optionally bound to a file path + + Returns: + _type_: _description_ + """ + file_path: Optional[str] location: Location type: DiagnosticType @@ -21,6 +30,18 @@ class Diagnostic: @property def location_str(self) -> str: + """The diagnostic type and location as a human readable string + + The location is formatted as " in from L: to :", + for example: "Error in /home/user/Desktop/script.py from L12:5 to L12:8" + + If the file is `None`, the "in ..." section is excluded from the result.
+ If the location's end is not specified, the formulation "at L:" is used. + + Returns: + str: _description_ + """ + start_loc: str = f"L{self.location.lineno}:{self.location.col_offset+1}" end_loc: Optional[str] = "" if (