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 adabb39 commit 2b008eb
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 22 deletions.
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
12 changes: 4 additions & 8 deletions mypy/typeanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1762,8 +1762,8 @@ def analyze_literal_param(self, idx: int, arg: Type, ctx: Context) -> list[Type]
self.fail(f"Parameter {idx} of Literal[...] is invalid", ctx, code=codes.VALID_TYPE)
return None

def analyze_type(self, t: Type) -> Type:
return t.accept(self)
def analyze_type(self, typ: Type) -> Type:
return typ.accept(self)

def fail(self, msg: str, ctx: Context, *, code: ErrorCode | None = None) -> None:
self.fail_func(msg, ctx, code=code)
Expand Down Expand Up @@ -1937,13 +1937,9 @@ def anal_var_defs(self, var_defs: Sequence[TypeVarLikeType]) -> list[TypeVarLike
return [self.anal_var_def(vd) for vd in var_defs]

def named_type(
self,
fully_qualified_name: str,
args: list[Type] | None = None,
line: int = -1,
column: int = -1,
self, name: str, args: list[Type] | None = None, line: int = -1, column: int = -1
) -> Instance:
node = self.lookup_fully_qualified(fully_qualified_name)
node = self.lookup_fully_qualified(name)
assert isinstance(node.node, TypeInfo)
any_type = AnyType(TypeOfAny.special_form)
if args is not None:
Expand Down

0 comments on commit 2b008eb

Please sign in to comment.