Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More LSP compatibility on arg names #18363

Merged
merged 4 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
hauntsaninja marked this conversation as resolved.
Show resolved Hide resolved
"""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:
hauntsaninja marked this conversation as resolved.
Show resolved Hide resolved
"""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,
/,
hauntsaninja marked this conversation as resolved.
Show resolved Hide resolved
*,
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:
hauntsaninja marked this conversation as resolved.
Show resolved Hide resolved
"""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:
hauntsaninja marked this conversation as resolved.
Show resolved Hide resolved
"""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:
hauntsaninja marked this conversation as resolved.
Show resolved Hide resolved
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:
hauntsaninja marked this conversation as resolved.
Show resolved Hide resolved
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,
/,
hauntsaninja marked this conversation as resolved.
Show resolved Hide resolved
*,
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
Loading