Skip to content

Commit 7090405

Browse files
committed
ci: fix some typecheck issues
Caught by running mypy with --check-untyped-defs. Claude (the robot) helped a bit with this, but it did some silly things that didn't match my intent (like annotating `tclfmt.py::check() path: Optional[pathlib.Path], ...)`, so I had make some tweaks. There are a few remaining issues to be cleaned up.
1 parent a01aab2 commit 7090405

File tree

5 files changed

+16
-16
lines changed

5 files changed

+16
-16
lines changed

src/tclint/checks.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ def visit_command(self, command):
119119

120120

121121
class UnbracedExprChecker(Visitor):
122-
def check(self, _, tree, __):
123-
self._violations = []
122+
def check(self, _, tree, __) -> list[Violation]:
123+
self._violations: list[Violation] = []
124124
tree.accept(self, recurse=True)
125125
return self._violations
126126

@@ -174,8 +174,8 @@ def visit_command(self, command):
174174

175175

176176
class RedundantExprChecker(Visitor):
177-
def check(self, _, tree, __):
178-
self._violations = []
177+
def check(self, _, tree, __) -> list[Violation]:
178+
self._violations: list[Violation] = []
179179
tree.accept(self, recurse=True)
180180
return self._violations
181181

src/tclint/cli/tclfmt.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def format(
4545
return formatter.format_top(script, parser)
4646

4747

48-
def check(path: pathlib.Path, script: str, formatted: str):
48+
def check(path: str, script: str, formatted: str):
4949
parser = Parser()
5050
original_tree = parser.parse(script)
5151
formatted_tree = parser.parse(formatted)
@@ -167,7 +167,7 @@ def main():
167167
print(formatted, end="")
168168

169169
if args.debug > 0:
170-
check(path, script, formatted)
170+
check(out_prefix, script, formatted)
171171
except TclSyntaxError as e:
172172
line, col = e.start
173173
print(f"{out_prefix}:{line}:{col}: syntax error: {e}", file=sys.stderr)

src/tclint/cli/tclsp.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def lint(source, config, plugin_manager, path):
6262
start=start,
6363
end=end,
6464
),
65-
code=violation.id,
65+
code=str(violation.id),
6666
source=DIAGNOSTIC_SOURCE,
6767
)
6868
)
@@ -443,7 +443,7 @@ def init(ls: TclspServer, params: lsp.InitializeParams):
443443
capabilities = ls.client_capabilities.workspace
444444

445445
try:
446-
ls.client_supports_refresh = (
446+
ls.client_supports_refresh = bool(
447447
capabilities.diagnostics.refresh_support # type: ignore[union-attr]
448448
)
449449
except AttributeError:
@@ -465,7 +465,7 @@ def init(ls: TclspServer, params: lsp.InitializeParams):
465465
for settings in (ls.global_settings, *ls.workspace_settings.values()):
466466
if settings.config_file is not None:
467467
watchers.append(
468-
lsp.FileSystemWatcher(glob_pattern=settings.config_file)
468+
lsp.FileSystemWatcher(glob_pattern=str(settings.config_file))
469469
)
470470

471471
ls.register_capability(

src/tclint/commands/builtin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
from tclint.commands.checks import CommandArgError, check_arg_spec, check_count, eval
3636
from tclint.commands.schema import commands_schema
37-
from tclint.syntax_tree import BareWord
37+
from tclint.syntax_tree import BareWord, Node
3838

3939

4040
def _check_code(arg):
@@ -432,7 +432,7 @@ def foreach(args, parser):
432432
def _if(args, parser):
433433
# ref: https://www.tcl-lang.org/man/tcl8.6/TclCmd/if.htm
434434

435-
new_args = []
435+
new_args: list[Node] = []
436436

437437
# Parse if condition.
438438
if len(new_args) == len(args):

src/tclint/commands/plugins.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66
from typing import Optional
77

88
import voluptuous
9-
from importlib_metadata import entry_points
9+
from importlib_metadata import EntryPoint, entry_points
1010

1111
from tclint.commands import builtin as _builtin
1212
from tclint.commands import schema
1313

1414

1515
class PluginManager:
1616
def __init__(self, trust_uninstalled=False):
17-
self._loaded = {}
18-
self._installed = {}
19-
self._loaded_specs = {}
20-
self._loaded_py = {}
17+
self._loaded: dict[str, Optional[dict]] = {}
18+
self._installed: dict[str, EntryPoint] = {}
19+
self._loaded_specs: dict[pathlib.Path, Optional[dict]] = {}
20+
self._loaded_py: dict[pathlib.Path, Optional[dict]] = {}
2121
for plugin in entry_points(group="tclint.plugins"):
2222
if plugin.name in self._installed:
2323
print(f"Warning: found duplicate definitions for plugin {plugin.name}")

0 commit comments

Comments
 (0)