Skip to content

Commit

Permalink
Ensure LSP on arg names
Browse files Browse the repository at this point in the history
Pairs well with python#18355
  • Loading branch information
hauntsaninja authored and cdce8p committed Dec 29, 2024
1 parent 9b9eb87 commit 57afee4
Show file tree
Hide file tree
Showing 11 changed files with 319 additions and 321 deletions.
32 changes: 16 additions & 16 deletions mypy/mixedtraverser.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ def __init__(self) -> None:

# Symbol nodes

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

def visit_func(self, o: FuncItem) -> None:
def visit_func(self, o: FuncItem, /) -> None:
super().visit_func(o)
self.visit_optional_type(o.type)

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

def visit_type_alias_expr(self, o: TypeAliasExpr) -> None:
def visit_type_alias_expr(self, o: TypeAliasExpr, /) -> None:
super().visit_type_alias_expr(o)
self.in_type_alias_expr = True
o.node.target.accept(self)
self.in_type_alias_expr = False

def visit_type_var_expr(self, o: TypeVarExpr) -> None:
def visit_type_var_expr(self, o: TypeVarExpr, /) -> None:
super().visit_type_var_expr(o)
o.upper_bound.accept(self)
for value in o.values:
value.accept(self)

def visit_typeddict_expr(self, o: TypedDictExpr) -> None:
def visit_typeddict_expr(self, o: TypedDictExpr, /) -> None:
super().visit_typeddict_expr(o)
self.visit_optional_type(o.info.typeddict_type)

def visit_namedtuple_expr(self, o: NamedTupleExpr) -> None:
def visit_namedtuple_expr(self, o: NamedTupleExpr, /) -> None:
super().visit_namedtuple_expr(o)
assert o.info.tuple_type
o.info.tuple_type.accept(self)

def visit__promote_expr(self, o: PromoteExpr) -> None:
def visit__promote_expr(self, o: PromoteExpr, /) -> None:
super().visit__promote_expr(o)
o.type.accept(self)

def visit_newtype_expr(self, o: NewTypeExpr) -> None:
def visit_newtype_expr(self, o: NewTypeExpr, /) -> None:
super().visit_newtype_expr(o)
self.visit_optional_type(o.old_type)

# Statements

def visit_assignment_stmt(self, o: AssignmentStmt) -> None:
def visit_assignment_stmt(self, o: AssignmentStmt, /) -> None:
super().visit_assignment_stmt(o)
self.visit_optional_type(o.type)

def visit_for_stmt(self, o: ForStmt) -> None:
def visit_for_stmt(self, o: ForStmt, /) -> None:
super().visit_for_stmt(o)
self.visit_optional_type(o.index_type)

def visit_with_stmt(self, o: WithStmt) -> None:
def visit_with_stmt(self, o: WithStmt, /) -> None:
super().visit_with_stmt(o)
for typ in o.analyzed_types:
typ.accept(self)

# Expressions

def visit_cast_expr(self, o: CastExpr) -> None:
def visit_cast_expr(self, o: CastExpr, /) -> None:
super().visit_cast_expr(o)
o.type.accept(self)

def visit_assert_type_expr(self, o: AssertTypeExpr) -> None:
def visit_assert_type_expr(self, o: AssertTypeExpr, /) -> None:
super().visit_assert_type_expr(o)
o.type.accept(self)

def visit_type_application(self, o: TypeApplication) -> None:
def visit_type_application(self, o: TypeApplication, /) -> None:
super().visit_type_application(o)
for t in o.types:
t.accept(self)

# Helpers

def visit_optional_type(self, t: Type | None) -> None:
def visit_optional_type(self, t: Type | None, /) -> None:
if t:
t.accept(self)
11 changes: 6 additions & 5 deletions mypy/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,8 @@ def fail(
@abstractmethod
def anal_type(
self,
t: Type,
typ: Type,
/,
*,
tvar_scope: TypeVarLikeScope | None = None,
allow_tuple_literal: bool = False,
Expand All @@ -340,15 +341,15 @@ def class_type(self, self_type: Type) -> Type:
raise NotImplementedError

@abstractmethod
def lookup_fully_qualified(self, name: str) -> SymbolTableNode:
def lookup_fully_qualified(self, fullname: str, /) -> SymbolTableNode:
"""Lookup a symbol by its fully qualified name.
Raise an error if not found.
"""
raise NotImplementedError

@abstractmethod
def lookup_fully_qualified_or_none(self, name: str) -> SymbolTableNode | None:
def lookup_fully_qualified_or_none(self, fullname: str, /) -> SymbolTableNode | None:
"""Lookup a symbol by its fully qualified name.
Return None if not found.
Expand Down Expand Up @@ -384,12 +385,12 @@ def add_plugin_dependency(self, trigger: str, target: str | None = None) -> None
raise NotImplementedError

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

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

Expand Down
2 changes: 1 addition & 1 deletion mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2090,7 +2090,7 @@ def analyze_namedtuple_classdef(
defn, self.is_stub_file, self.is_func_scope()
)
if is_named_tuple:
if info is None:
if info is None or any(has_placeholder(tv) for tv in tvar_defs):
self.mark_incomplete(defn.name, defn)
else:
self.prepare_class_def(defn, info, custom_names=True)
Expand Down
15 changes: 8 additions & 7 deletions mypy/semanal_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ def lookup_qualified(
raise NotImplementedError

@abstractmethod
def lookup_fully_qualified(self, name: str) -> SymbolTableNode:
def lookup_fully_qualified(self, fullname: str, /) -> SymbolTableNode:
raise NotImplementedError

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

@abstractmethod
Expand Down Expand Up @@ -176,7 +176,8 @@ def accept(self, node: Node) -> None:
@abstractmethod
def anal_type(
self,
t: Type,
typ: Type,
/,
*,
tvar_scope: TypeVarLikeScope | None = None,
allow_tuple_literal: bool = False,
Expand All @@ -198,11 +199,11 @@ def basic_new_typeinfo(self, name: str, basetype_or_fallback: Instance, line: in
raise NotImplementedError

@abstractmethod
def schedule_patch(self, priority: int, fn: Callable[[], None]) -> None:
def schedule_patch(self, priority: int, patch: Callable[[], None], /) -> None:
raise NotImplementedError

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

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

@abstractmethod
def qualified_name(self, n: str) -> str:
def qualified_name(self, n: str, /) -> str:
raise NotImplementedError

@property
Expand Down Expand Up @@ -309,7 +310,7 @@ def calculate_tuple_fallback(typ: TupleType) -> None:


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


def paramspec_args(
Expand Down
2 changes: 1 addition & 1 deletion mypy/test/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -816,5 +816,5 @@ def setup(self) -> None:
"""Setup fixtures (ad-hoc)"""

@abstractmethod
def run_case(self, testcase: DataDrivenTestCase) -> None:
def run_case(self, test_case: DataDrivenTestCase, /) -> None:
raise NotImplementedError
22 changes: 11 additions & 11 deletions mypy/test/test_find_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ class FakeFSCache(FileSystemCache):
def __init__(self, files: set[str]) -> None:
self.files = {os.path.abspath(f) for f in files}

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

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

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

def init_under_package_root(self, file: str) -> bool:
def init_under_package_root(self, path: str) -> bool:
return False


Expand Down
Loading

0 comments on commit 57afee4

Please sign in to comment.