Skip to content

Commit 9b6f29e

Browse files
committed
Ensure LSP on arg names
Pairs well with python#18355
1 parent 6d13d0d commit 9b6f29e

11 files changed

+319
-317
lines changed

mypy/mixedtraverser.py

+16-16
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ def __init__(self) -> None:
3030

3131
# Symbol nodes
3232

33-
def visit_var(self, var: Var) -> None:
33+
def visit_var(self, var: Var, /) -> None:
3434
self.visit_optional_type(var.type)
3535

36-
def visit_func(self, o: FuncItem) -> None:
36+
def visit_func(self, o: FuncItem, /) -> None:
3737
super().visit_func(o)
3838
self.visit_optional_type(o.type)
3939

40-
def visit_class_def(self, o: ClassDef) -> None:
40+
def visit_class_def(self, o: ClassDef, /) -> None:
4141
# TODO: Should we visit generated methods/variables as well, either here or in
4242
# TraverserVisitor?
4343
super().visit_class_def(o)
@@ -46,67 +46,67 @@ def visit_class_def(self, o: ClassDef) -> None:
4646
for base in info.bases:
4747
base.accept(self)
4848

49-
def visit_type_alias_expr(self, o: TypeAliasExpr) -> None:
49+
def visit_type_alias_expr(self, o: TypeAliasExpr, /) -> None:
5050
super().visit_type_alias_expr(o)
5151
self.in_type_alias_expr = True
5252
o.node.target.accept(self)
5353
self.in_type_alias_expr = False
5454

55-
def visit_type_var_expr(self, o: TypeVarExpr) -> None:
55+
def visit_type_var_expr(self, o: TypeVarExpr, /) -> None:
5656
super().visit_type_var_expr(o)
5757
o.upper_bound.accept(self)
5858
for value in o.values:
5959
value.accept(self)
6060

61-
def visit_typeddict_expr(self, o: TypedDictExpr) -> None:
61+
def visit_typeddict_expr(self, o: TypedDictExpr, /) -> None:
6262
super().visit_typeddict_expr(o)
6363
self.visit_optional_type(o.info.typeddict_type)
6464

65-
def visit_namedtuple_expr(self, o: NamedTupleExpr) -> None:
65+
def visit_namedtuple_expr(self, o: NamedTupleExpr, /) -> None:
6666
super().visit_namedtuple_expr(o)
6767
assert o.info.tuple_type
6868
o.info.tuple_type.accept(self)
6969

70-
def visit__promote_expr(self, o: PromoteExpr) -> None:
70+
def visit__promote_expr(self, o: PromoteExpr, /) -> None:
7171
super().visit__promote_expr(o)
7272
o.type.accept(self)
7373

74-
def visit_newtype_expr(self, o: NewTypeExpr) -> None:
74+
def visit_newtype_expr(self, o: NewTypeExpr, /) -> None:
7575
super().visit_newtype_expr(o)
7676
self.visit_optional_type(o.old_type)
7777

7878
# Statements
7979

80-
def visit_assignment_stmt(self, o: AssignmentStmt) -> None:
80+
def visit_assignment_stmt(self, o: AssignmentStmt, /) -> None:
8181
super().visit_assignment_stmt(o)
8282
self.visit_optional_type(o.type)
8383

84-
def visit_for_stmt(self, o: ForStmt) -> None:
84+
def visit_for_stmt(self, o: ForStmt, /) -> None:
8585
super().visit_for_stmt(o)
8686
self.visit_optional_type(o.index_type)
8787

88-
def visit_with_stmt(self, o: WithStmt) -> None:
88+
def visit_with_stmt(self, o: WithStmt, /) -> None:
8989
super().visit_with_stmt(o)
9090
for typ in o.analyzed_types:
9191
typ.accept(self)
9292

9393
# Expressions
9494

95-
def visit_cast_expr(self, o: CastExpr) -> None:
95+
def visit_cast_expr(self, o: CastExpr, /) -> None:
9696
super().visit_cast_expr(o)
9797
o.type.accept(self)
9898

99-
def visit_assert_type_expr(self, o: AssertTypeExpr) -> None:
99+
def visit_assert_type_expr(self, o: AssertTypeExpr, /) -> None:
100100
super().visit_assert_type_expr(o)
101101
o.type.accept(self)
102102

103-
def visit_type_application(self, o: TypeApplication) -> None:
103+
def visit_type_application(self, o: TypeApplication, /) -> None:
104104
super().visit_type_application(o)
105105
for t in o.types:
106106
t.accept(self)
107107

108108
# Helpers
109109

110-
def visit_optional_type(self, t: Type | None) -> None:
110+
def visit_optional_type(self, t: Type | None, /) -> None:
111111
if t:
112112
t.accept(self)

mypy/plugin.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,8 @@ def fail(
319319
@abstractmethod
320320
def anal_type(
321321
self,
322-
t: Type,
322+
typ: Type,
323+
/,
323324
*,
324325
tvar_scope: TypeVarLikeScope | None = None,
325326
allow_tuple_literal: bool = False,
@@ -340,15 +341,15 @@ def class_type(self, self_type: Type) -> Type:
340341
raise NotImplementedError
341342

342343
@abstractmethod
343-
def lookup_fully_qualified(self, name: str) -> SymbolTableNode:
344+
def lookup_fully_qualified(self, fullname: str, /) -> SymbolTableNode:
344345
"""Lookup a symbol by its fully qualified name.
345346
346347
Raise an error if not found.
347348
"""
348349
raise NotImplementedError
349350

350351
@abstractmethod
351-
def lookup_fully_qualified_or_none(self, name: str) -> SymbolTableNode | None:
352+
def lookup_fully_qualified_or_none(self, fullname: str, /) -> SymbolTableNode | None:
352353
"""Lookup a symbol by its fully qualified name.
353354
354355
Return None if not found.
@@ -384,12 +385,12 @@ def add_plugin_dependency(self, trigger: str, target: str | None = None) -> None
384385
raise NotImplementedError
385386

386387
@abstractmethod
387-
def add_symbol_table_node(self, name: str, stnode: SymbolTableNode) -> Any:
388+
def add_symbol_table_node(self, name: str, symbol: SymbolTableNode, /) -> Any:
388389
"""Add node to global symbol table (or to nearest class if there is one)."""
389390
raise NotImplementedError
390391

391392
@abstractmethod
392-
def qualified_name(self, n: str) -> str:
393+
def qualified_name(self, n: str, /) -> str:
393394
"""Make qualified name using current module and enclosing class (if any)."""
394395
raise NotImplementedError
395396

mypy/semanal.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2090,7 +2090,7 @@ def analyze_namedtuple_classdef(
20902090
defn, self.is_stub_file, self.is_func_scope()
20912091
)
20922092
if is_named_tuple:
2093-
if info is None:
2093+
if info is None or any(has_placeholder(tv) for tv in tvar_defs):
20942094
self.mark_incomplete(defn.name, defn)
20952095
else:
20962096
self.prepare_class_def(defn, info, custom_names=True)

mypy/semanal_shared.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ def lookup_qualified(
7676
raise NotImplementedError
7777

7878
@abstractmethod
79-
def lookup_fully_qualified(self, name: str) -> SymbolTableNode:
79+
def lookup_fully_qualified(self, fullname: str, /) -> SymbolTableNode:
8080
raise NotImplementedError
8181

8282
@abstractmethod
83-
def lookup_fully_qualified_or_none(self, name: str) -> SymbolTableNode | None:
83+
def lookup_fully_qualified_or_none(self, fullname: str, /) -> SymbolTableNode | None:
8484
raise NotImplementedError
8585

8686
@abstractmethod
@@ -176,7 +176,8 @@ def accept(self, node: Node) -> None:
176176
@abstractmethod
177177
def anal_type(
178178
self,
179-
t: Type,
179+
typ: Type,
180+
/,
180181
*,
181182
tvar_scope: TypeVarLikeScope | None = None,
182183
allow_tuple_literal: bool = False,
@@ -198,11 +199,11 @@ def basic_new_typeinfo(self, name: str, basetype_or_fallback: Instance, line: in
198199
raise NotImplementedError
199200

200201
@abstractmethod
201-
def schedule_patch(self, priority: int, fn: Callable[[], None]) -> None:
202+
def schedule_patch(self, priority: int, patch: Callable[[], None], /) -> None:
202203
raise NotImplementedError
203204

204205
@abstractmethod
205-
def add_symbol_table_node(self, name: str, stnode: SymbolTableNode) -> bool:
206+
def add_symbol_table_node(self, name: str, symbol: SymbolTableNode, /) -> bool:
206207
"""Add node to the current symbol table."""
207208
raise NotImplementedError
208209

@@ -242,7 +243,7 @@ def parse_bool(self, expr: Expression) -> bool | None:
242243
raise NotImplementedError
243244

244245
@abstractmethod
245-
def qualified_name(self, n: str) -> str:
246+
def qualified_name(self, n: str, /) -> str:
246247
raise NotImplementedError
247248

248249
@property
@@ -309,7 +310,7 @@ def calculate_tuple_fallback(typ: TupleType) -> None:
309310

310311

311312
class _NamedTypeCallback(Protocol):
312-
def __call__(self, fully_qualified_name: str, args: list[Type] | None = None) -> Instance: ...
313+
def __call__(self, name: str, args: list[Type] | None = None) -> Instance: ...
313314

314315

315316
def paramspec_args(

mypy/test/data.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -816,5 +816,5 @@ def setup(self) -> None:
816816
"""Setup fixtures (ad-hoc)"""
817817

818818
@abstractmethod
819-
def run_case(self, testcase: DataDrivenTestCase) -> None:
819+
def run_case(self, test_case: DataDrivenTestCase, /) -> None:
820820
raise NotImplementedError

mypy/test/test_find_sources.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,20 @@ class FakeFSCache(FileSystemCache):
1717
def __init__(self, files: set[str]) -> None:
1818
self.files = {os.path.abspath(f) for f in files}
1919

20-
def isfile(self, file: str) -> bool:
21-
return file in self.files
20+
def isfile(self, path: str) -> bool:
21+
return path in self.files
2222

23-
def isdir(self, dir: str) -> bool:
24-
if not dir.endswith(os.sep):
25-
dir += os.sep
26-
return any(f.startswith(dir) for f in self.files)
23+
def isdir(self, path: str) -> bool:
24+
if not path.endswith(os.sep):
25+
path += os.sep
26+
return any(f.startswith(path) for f in self.files)
2727

28-
def listdir(self, dir: str) -> list[str]:
29-
if not dir.endswith(os.sep):
30-
dir += os.sep
31-
return list({f[len(dir) :].split(os.sep)[0] for f in self.files if f.startswith(dir)})
28+
def listdir(self, path: str) -> list[str]:
29+
if not path.endswith(os.sep):
30+
path += os.sep
31+
return list({f[len(path) :].split(os.sep)[0] for f in self.files if f.startswith(path)})
3232

33-
def init_under_package_root(self, file: str) -> bool:
33+
def init_under_package_root(self, path: str) -> bool:
3434
return False
3535

3636

0 commit comments

Comments
 (0)