Skip to content

Commit

Permalink
More LSP compatibility on arg names (#18363)
Browse files Browse the repository at this point in the history
Got lost when #18356 was broken up
  • Loading branch information
hauntsaninja authored Dec 30, 2024
1 parent 4a0b331 commit c821503
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 24 deletions.
15 changes: 8 additions & 7 deletions mypy/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,12 @@ def fail(self, msg: str, ctx: Context, *, code: ErrorCode | None = None) -> None
raise NotImplementedError

@abstractmethod
def named_type(self, name: str, args: list[Type]) -> Instance:
def named_type(self, fullname: str, args: list[Type], /) -> Instance:
"""Construct an instance of a builtin type with given name."""
raise NotImplementedError

@abstractmethod
def analyze_type(self, typ: Type) -> Type:
def analyze_type(self, typ: Type, /) -> Type:
"""Analyze an unbound type using the default mypy logic."""
raise NotImplementedError

Expand Down 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, name: str) -> str:
"""Make qualified name using current module and enclosing class (if any)."""
raise NotImplementedError

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, name: 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, fullname: str, args: list[Type] | None = None) -> Instance: ...


def paramspec_args(
Expand Down
16 changes: 6 additions & 10 deletions mypy/typeanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ def lookup_qualified(
) -> SymbolTableNode | None:
return self.api.lookup_qualified(name, ctx, suppress_errors)

def lookup_fully_qualified(self, name: str) -> SymbolTableNode:
return self.api.lookup_fully_qualified(name)
def lookup_fully_qualified(self, fullname: str) -> SymbolTableNode:
return self.api.lookup_fully_qualified(fullname)

def visit_unbound_type(self, t: UnboundType, defining_literal: bool = False) -> Type:
typ = self.visit_unbound_type_nonoptional(t, defining_literal)
Expand Down 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, fullname: 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(fullname)
assert isinstance(node.node, TypeInfo)
any_type = AnyType(TypeOfAny.special_form)
if args is not None:
Expand Down

0 comments on commit c821503

Please sign in to comment.