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

Ensure LSP compatibility on arg names in mypy #18356

Closed
wants to merge 2 commits into from
Closed
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
32 changes: 16 additions & 16 deletions mypy/mixedtraverser.py
Original file line number Diff line number Diff line change
@@ -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)
@@ -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
@@ -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,
@@ -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.
@@ -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

2 changes: 1 addition & 1 deletion mypy/semanal.py
Original file line number Diff line number Diff line change
@@ -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):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like the change from #18351

self.mark_incomplete(defn.name, defn)
else:
self.prepare_class_def(defn, info, custom_names=True)
15 changes: 8 additions & 7 deletions mypy/semanal_shared.py
Original file line number Diff line number Diff line change
@@ -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
@@ -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,
@@ -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

@@ -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
@@ -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(
2 changes: 1 addition & 1 deletion mypy/test/data.py
Original file line number Diff line number Diff line change
@@ -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
@@ -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


114 changes: 57 additions & 57 deletions mypy/traverser.py
Original file line number Diff line number Diff line change
@@ -111,15 +111,15 @@ def __init__(self) -> None:

# Visit methods

def visit_mypy_file(self, o: MypyFile) -> None:
def visit_mypy_file(self, o: MypyFile, /) -> None:
for d in o.defs:
d.accept(self)

def visit_block(self, block: Block) -> None:
def visit_block(self, block: Block, /) -> None:
for s in block.body:
s.accept(self)

def visit_func(self, o: FuncItem) -> None:
def visit_func(self, o: FuncItem, /) -> None:
if o.arguments is not None:
for arg in o.arguments:
init = arg.initializer
@@ -131,16 +131,16 @@ def visit_func(self, o: FuncItem) -> None:

o.body.accept(self)

def visit_func_def(self, o: FuncDef) -> None:
def visit_func_def(self, o: FuncDef, /) -> None:
self.visit_func(o)

def visit_overloaded_func_def(self, o: OverloadedFuncDef) -> None:
def visit_overloaded_func_def(self, o: OverloadedFuncDef, /) -> None:
for item in o.items:
item.accept(self)
if o.impl:
o.impl.accept(self)

def visit_class_def(self, o: ClassDef) -> None:
def visit_class_def(self, o: ClassDef, /) -> None:
for d in o.decorators:
d.accept(self)
for base in o.base_type_exprs:
@@ -153,66 +153,66 @@ def visit_class_def(self, o: ClassDef) -> None:
if o.analyzed:
o.analyzed.accept(self)

def visit_decorator(self, o: Decorator) -> None:
def visit_decorator(self, o: Decorator, /) -> None:
o.func.accept(self)
o.var.accept(self)
for decorator in o.decorators:
decorator.accept(self)

def visit_expression_stmt(self, o: ExpressionStmt) -> None:
def visit_expression_stmt(self, o: ExpressionStmt, /) -> None:
o.expr.accept(self)

def visit_assignment_stmt(self, o: AssignmentStmt) -> None:
def visit_assignment_stmt(self, o: AssignmentStmt, /) -> None:
o.rvalue.accept(self)
for l in o.lvalues:
l.accept(self)

def visit_operator_assignment_stmt(self, o: OperatorAssignmentStmt) -> None:
def visit_operator_assignment_stmt(self, o: OperatorAssignmentStmt, /) -> None:
o.rvalue.accept(self)
o.lvalue.accept(self)

def visit_while_stmt(self, o: WhileStmt) -> None:
def visit_while_stmt(self, o: WhileStmt, /) -> None:
o.expr.accept(self)
o.body.accept(self)
if o.else_body:
o.else_body.accept(self)

def visit_for_stmt(self, o: ForStmt) -> None:
def visit_for_stmt(self, o: ForStmt, /) -> None:
o.index.accept(self)
o.expr.accept(self)
o.body.accept(self)
if o.else_body:
o.else_body.accept(self)

def visit_return_stmt(self, o: ReturnStmt) -> None:
def visit_return_stmt(self, o: ReturnStmt, /) -> None:
if o.expr is not None:
o.expr.accept(self)

def visit_assert_stmt(self, o: AssertStmt) -> None:
def visit_assert_stmt(self, o: AssertStmt, /) -> None:
if o.expr is not None:
o.expr.accept(self)
if o.msg is not None:
o.msg.accept(self)

def visit_del_stmt(self, o: DelStmt) -> None:
def visit_del_stmt(self, o: DelStmt, /) -> None:
if o.expr is not None:
o.expr.accept(self)

def visit_if_stmt(self, o: IfStmt) -> None:
def visit_if_stmt(self, o: IfStmt, /) -> None:
for e in o.expr:
e.accept(self)
for b in o.body:
b.accept(self)
if o.else_body:
o.else_body.accept(self)

def visit_raise_stmt(self, o: RaiseStmt) -> None:
def visit_raise_stmt(self, o: RaiseStmt, /) -> None:
if o.expr is not None:
o.expr.accept(self)
if o.from_expr is not None:
o.from_expr.accept(self)

def visit_try_stmt(self, o: TryStmt) -> None:
def visit_try_stmt(self, o: TryStmt, /) -> None:
o.body.accept(self)
for i in range(len(o.types)):
tp = o.types[i]
@@ -227,15 +227,15 @@ def visit_try_stmt(self, o: TryStmt) -> None:
if o.finally_body is not None:
o.finally_body.accept(self)

def visit_with_stmt(self, o: WithStmt) -> None:
def visit_with_stmt(self, o: WithStmt, /) -> None:
for i in range(len(o.expr)):
o.expr[i].accept(self)
targ = o.target[i]
if targ is not None:
targ.accept(self)
o.body.accept(self)

def visit_match_stmt(self, o: MatchStmt) -> None:
def visit_match_stmt(self, o: MatchStmt, /) -> None:
o.subject.accept(self)
for i in range(len(o.patterns)):
o.patterns[i].accept(self)
@@ -244,99 +244,99 @@ def visit_match_stmt(self, o: MatchStmt) -> None:
guard.accept(self)
o.bodies[i].accept(self)

def visit_type_alias_stmt(self, o: TypeAliasStmt) -> None:
def visit_type_alias_stmt(self, o: TypeAliasStmt, /) -> None:
o.name.accept(self)
o.value.accept(self)

def visit_member_expr(self, o: MemberExpr) -> None:
def visit_member_expr(self, o: MemberExpr, /) -> None:
o.expr.accept(self)

def visit_yield_from_expr(self, o: YieldFromExpr) -> None:
def visit_yield_from_expr(self, o: YieldFromExpr, /) -> None:
o.expr.accept(self)

def visit_yield_expr(self, o: YieldExpr) -> None:
def visit_yield_expr(self, o: YieldExpr, /) -> None:
if o.expr:
o.expr.accept(self)

def visit_call_expr(self, o: CallExpr) -> None:
def visit_call_expr(self, o: CallExpr, /) -> None:
o.callee.accept(self)
for a in o.args:
a.accept(self)
if o.analyzed:
o.analyzed.accept(self)

def visit_op_expr(self, o: OpExpr) -> None:
def visit_op_expr(self, o: OpExpr, /) -> None:
o.left.accept(self)
o.right.accept(self)
if o.analyzed is not None:
o.analyzed.accept(self)

def visit_comparison_expr(self, o: ComparisonExpr) -> None:
def visit_comparison_expr(self, o: ComparisonExpr, /) -> None:
for operand in o.operands:
operand.accept(self)

def visit_slice_expr(self, o: SliceExpr) -> None:
def visit_slice_expr(self, o: SliceExpr, /) -> None:
if o.begin_index is not None:
o.begin_index.accept(self)
if o.end_index is not None:
o.end_index.accept(self)
if o.stride is not None:
o.stride.accept(self)

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

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

def visit_reveal_expr(self, o: RevealExpr) -> None:
def visit_reveal_expr(self, o: RevealExpr, /) -> None:
if o.kind == REVEAL_TYPE:
assert o.expr is not None
o.expr.accept(self)
else:
# RevealLocalsExpr doesn't have an inner expression
pass

def visit_assignment_expr(self, o: AssignmentExpr) -> None:
def visit_assignment_expr(self, o: AssignmentExpr, /) -> None:
o.target.accept(self)
o.value.accept(self)

def visit_unary_expr(self, o: UnaryExpr) -> None:
def visit_unary_expr(self, o: UnaryExpr, /) -> None:
o.expr.accept(self)

def visit_list_expr(self, o: ListExpr) -> None:
def visit_list_expr(self, o: ListExpr, /) -> None:
for item in o.items:
item.accept(self)

def visit_tuple_expr(self, o: TupleExpr) -> None:
def visit_tuple_expr(self, o: TupleExpr, /) -> None:
for item in o.items:
item.accept(self)

def visit_dict_expr(self, o: DictExpr) -> None:
def visit_dict_expr(self, o: DictExpr, /) -> None:
for k, v in o.items:
if k is not None:
k.accept(self)
v.accept(self)

def visit_set_expr(self, o: SetExpr) -> None:
def visit_set_expr(self, o: SetExpr, /) -> None:
for item in o.items:
item.accept(self)

def visit_index_expr(self, o: IndexExpr) -> None:
def visit_index_expr(self, o: IndexExpr, /) -> None:
o.base.accept(self)
o.index.accept(self)
if o.analyzed:
o.analyzed.accept(self)

def visit_generator_expr(self, o: GeneratorExpr) -> None:
def visit_generator_expr(self, o: GeneratorExpr, /) -> None:
for index, sequence, conditions in zip(o.indices, o.sequences, o.condlists):
sequence.accept(self)
index.accept(self)
for cond in conditions:
cond.accept(self)
o.left_expr.accept(self)

def visit_dictionary_comprehension(self, o: DictionaryComprehension) -> None:
def visit_dictionary_comprehension(self, o: DictionaryComprehension, /) -> None:
for index, sequence, conditions in zip(o.indices, o.sequences, o.condlists):
sequence.accept(self)
index.accept(self)
@@ -345,73 +345,73 @@ def visit_dictionary_comprehension(self, o: DictionaryComprehension) -> None:
o.key.accept(self)
o.value.accept(self)

def visit_list_comprehension(self, o: ListComprehension) -> None:
def visit_list_comprehension(self, o: ListComprehension, /) -> None:
o.generator.accept(self)

def visit_set_comprehension(self, o: SetComprehension) -> None:
def visit_set_comprehension(self, o: SetComprehension, /) -> None:
o.generator.accept(self)

def visit_conditional_expr(self, o: ConditionalExpr) -> None:
def visit_conditional_expr(self, o: ConditionalExpr, /) -> None:
o.cond.accept(self)
o.if_expr.accept(self)
o.else_expr.accept(self)

def visit_type_application(self, o: TypeApplication) -> None:
def visit_type_application(self, o: TypeApplication, /) -> None:
o.expr.accept(self)

def visit_lambda_expr(self, o: LambdaExpr) -> None:
def visit_lambda_expr(self, o: LambdaExpr, /) -> None:
self.visit_func(o)

def visit_star_expr(self, o: StarExpr) -> None:
def visit_star_expr(self, o: StarExpr, /) -> None:
o.expr.accept(self)

def visit_await_expr(self, o: AwaitExpr) -> None:
def visit_await_expr(self, o: AwaitExpr, /) -> None:
o.expr.accept(self)

def visit_super_expr(self, o: SuperExpr) -> None:
def visit_super_expr(self, o: SuperExpr, /) -> None:
o.call.accept(self)

def visit_as_pattern(self, o: AsPattern) -> None:
def visit_as_pattern(self, o: AsPattern, /) -> None:
if o.pattern is not None:
o.pattern.accept(self)
if o.name is not None:
o.name.accept(self)

def visit_or_pattern(self, o: OrPattern) -> None:
def visit_or_pattern(self, o: OrPattern, /) -> None:
for p in o.patterns:
p.accept(self)

def visit_value_pattern(self, o: ValuePattern) -> None:
def visit_value_pattern(self, o: ValuePattern, /) -> None:
o.expr.accept(self)

def visit_sequence_pattern(self, o: SequencePattern) -> None:
def visit_sequence_pattern(self, o: SequencePattern, /) -> None:
for p in o.patterns:
p.accept(self)

def visit_starred_pattern(self, o: StarredPattern) -> None:
def visit_starred_pattern(self, o: StarredPattern, /) -> None:
if o.capture is not None:
o.capture.accept(self)

def visit_mapping_pattern(self, o: MappingPattern) -> None:
def visit_mapping_pattern(self, o: MappingPattern, /) -> None:
for key in o.keys:
key.accept(self)
for value in o.values:
value.accept(self)
if o.rest is not None:
o.rest.accept(self)

def visit_class_pattern(self, o: ClassPattern) -> None:
def visit_class_pattern(self, o: ClassPattern, /) -> None:
o.class_ref.accept(self)
for p in o.positionals:
p.accept(self)
for v in o.keyword_values:
v.accept(self)

def visit_import(self, o: Import) -> None:
def visit_import(self, o: Import, /) -> None:
for a in o.assignments:
a.accept(self)

def visit_import_from(self, o: ImportFrom) -> None:
def visit_import_from(self, o: ImportFrom, /) -> None:
for a in o.assignments:
a.accept(self)

52 changes: 26 additions & 26 deletions mypy/type_visitor.py
Original file line number Diff line number Diff line change
@@ -62,87 +62,87 @@ class TypeVisitor(Generic[T]):
"""

@abstractmethod
def visit_unbound_type(self, t: UnboundType) -> T:
def visit_unbound_type(self, t: UnboundType, /) -> T:
pass

@abstractmethod
def visit_any(self, t: AnyType) -> T:
def visit_any(self, t: AnyType, /) -> T:
pass

@abstractmethod
def visit_none_type(self, t: NoneType) -> T:
def visit_none_type(self, t: NoneType, /) -> T:
pass

@abstractmethod
def visit_uninhabited_type(self, t: UninhabitedType) -> T:
def visit_uninhabited_type(self, t: UninhabitedType, /) -> T:
pass

@abstractmethod
def visit_erased_type(self, t: ErasedType) -> T:
def visit_erased_type(self, t: ErasedType, /) -> T:
pass

@abstractmethod
def visit_deleted_type(self, t: DeletedType) -> T:
def visit_deleted_type(self, t: DeletedType, /) -> T:
pass

@abstractmethod
def visit_type_var(self, t: TypeVarType) -> T:
def visit_type_var(self, t: TypeVarType, /) -> T:
pass

@abstractmethod
def visit_param_spec(self, t: ParamSpecType) -> T:
def visit_param_spec(self, t: ParamSpecType, /) -> T:
pass

@abstractmethod
def visit_parameters(self, t: Parameters) -> T:
def visit_parameters(self, t: Parameters, /) -> T:
pass

@abstractmethod
def visit_type_var_tuple(self, t: TypeVarTupleType) -> T:
def visit_type_var_tuple(self, t: TypeVarTupleType, /) -> T:
pass

@abstractmethod
def visit_instance(self, t: Instance) -> T:
def visit_instance(self, t: Instance, /) -> T:
pass

@abstractmethod
def visit_callable_type(self, t: CallableType) -> T:
def visit_callable_type(self, t: CallableType, /) -> T:
pass

@abstractmethod
def visit_overloaded(self, t: Overloaded) -> T:
def visit_overloaded(self, t: Overloaded, /) -> T:
pass

@abstractmethod
def visit_tuple_type(self, t: TupleType) -> T:
def visit_tuple_type(self, t: TupleType, /) -> T:
pass

@abstractmethod
def visit_typeddict_type(self, t: TypedDictType) -> T:
def visit_typeddict_type(self, t: TypedDictType, /) -> T:
pass

@abstractmethod
def visit_literal_type(self, t: LiteralType) -> T:
def visit_literal_type(self, t: LiteralType, /) -> T:
pass

@abstractmethod
def visit_union_type(self, t: UnionType) -> T:
def visit_union_type(self, t: UnionType, /) -> T:
pass

@abstractmethod
def visit_partial_type(self, t: PartialType) -> T:
def visit_partial_type(self, t: PartialType, /) -> T:
pass

@abstractmethod
def visit_type_type(self, t: TypeType) -> T:
def visit_type_type(self, t: TypeType, /) -> T:
pass

@abstractmethod
def visit_type_alias_type(self, t: TypeAliasType) -> T:
def visit_type_alias_type(self, t: TypeAliasType, /) -> T:
pass

@abstractmethod
def visit_unpack_type(self, t: UnpackType) -> T:
def visit_unpack_type(self, t: UnpackType, /) -> T:
pass


@@ -155,23 +155,23 @@ class SyntheticTypeVisitor(TypeVisitor[T]):
"""

@abstractmethod
def visit_type_list(self, t: TypeList) -> T:
def visit_type_list(self, t: TypeList, /) -> T:
pass

@abstractmethod
def visit_callable_argument(self, t: CallableArgument) -> T:
def visit_callable_argument(self, t: CallableArgument, /) -> T:
pass

@abstractmethod
def visit_ellipsis_type(self, t: EllipsisType) -> T:
def visit_ellipsis_type(self, t: EllipsisType, /) -> T:
pass

@abstractmethod
def visit_raw_expression_type(self, t: RawExpressionType) -> T:
def visit_raw_expression_type(self, t: RawExpressionType, /) -> T:
pass

@abstractmethod
def visit_placeholder_type(self, t: PlaceholderType) -> T:
def visit_placeholder_type(self, t: PlaceholderType, /) -> T:
pass


12 changes: 4 additions & 8 deletions mypy/typeanal.py
Original file line number Diff line number Diff line change
@@ -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)
@@ -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:
54 changes: 27 additions & 27 deletions mypy/typetraverser.py
Original file line number Diff line number Diff line change
@@ -42,45 +42,45 @@ class TypeTraverserVisitor(SyntheticTypeVisitor[None]):

# Atomic types

def visit_any(self, t: AnyType) -> None:
def visit_any(self, t: AnyType, /) -> None:
pass

def visit_uninhabited_type(self, t: UninhabitedType) -> None:
def visit_uninhabited_type(self, t: UninhabitedType, /) -> None:
pass

def visit_none_type(self, t: NoneType) -> None:
def visit_none_type(self, t: NoneType, /) -> None:
pass

def visit_erased_type(self, t: ErasedType) -> None:
def visit_erased_type(self, t: ErasedType, /) -> None:
pass

def visit_deleted_type(self, t: DeletedType) -> None:
def visit_deleted_type(self, t: DeletedType, /) -> None:
pass

def visit_type_var(self, t: TypeVarType) -> None:
def visit_type_var(self, t: TypeVarType, /) -> None:
# Note that type variable values and upper bound aren't treated as
# components, since they are components of the type variable
# definition. We want to traverse everything just once.
t.default.accept(self)

def visit_param_spec(self, t: ParamSpecType) -> None:
def visit_param_spec(self, t: ParamSpecType, /) -> None:
t.default.accept(self)

def visit_parameters(self, t: Parameters) -> None:
def visit_parameters(self, t: Parameters, /) -> None:
self.traverse_types(t.arg_types)

def visit_type_var_tuple(self, t: TypeVarTupleType) -> None:
def visit_type_var_tuple(self, t: TypeVarTupleType, /) -> None:
t.default.accept(self)

def visit_literal_type(self, t: LiteralType) -> None:
def visit_literal_type(self, t: LiteralType, /) -> None:
t.fallback.accept(self)

# Composite types

def visit_instance(self, t: Instance) -> None:
def visit_instance(self, t: Instance, /) -> None:
self.traverse_types(t.args)

def visit_callable_type(self, t: CallableType) -> None:
def visit_callable_type(self, t: CallableType, /) -> None:
# FIX generics
self.traverse_types(t.arg_types)
t.ret_type.accept(self)
@@ -92,57 +92,57 @@ def visit_callable_type(self, t: CallableType) -> None:
if t.type_is is not None:
t.type_is.accept(self)

def visit_tuple_type(self, t: TupleType) -> None:
def visit_tuple_type(self, t: TupleType, /) -> None:
self.traverse_types(t.items)
t.partial_fallback.accept(self)

def visit_typeddict_type(self, t: TypedDictType) -> None:
def visit_typeddict_type(self, t: TypedDictType, /) -> None:
self.traverse_types(t.items.values())
t.fallback.accept(self)

def visit_union_type(self, t: UnionType) -> None:
def visit_union_type(self, t: UnionType, /) -> None:
self.traverse_types(t.items)

def visit_overloaded(self, t: Overloaded) -> None:
def visit_overloaded(self, t: Overloaded, /) -> None:
self.traverse_types(t.items)

def visit_type_type(self, t: TypeType) -> None:
def visit_type_type(self, t: TypeType, /) -> None:
t.item.accept(self)

# Special types (not real types)

def visit_callable_argument(self, t: CallableArgument) -> None:
def visit_callable_argument(self, t: CallableArgument, /) -> None:
t.typ.accept(self)

def visit_unbound_type(self, t: UnboundType) -> None:
def visit_unbound_type(self, t: UnboundType, /) -> None:
self.traverse_types(t.args)

def visit_type_list(self, t: TypeList) -> None:
def visit_type_list(self, t: TypeList, /) -> None:
self.traverse_types(t.items)

def visit_ellipsis_type(self, t: EllipsisType) -> None:
def visit_ellipsis_type(self, t: EllipsisType, /) -> None:
pass

def visit_placeholder_type(self, t: PlaceholderType) -> None:
def visit_placeholder_type(self, t: PlaceholderType, /) -> None:
self.traverse_types(t.args)

def visit_partial_type(self, t: PartialType) -> None:
def visit_partial_type(self, t: PartialType, /) -> None:
pass

def visit_raw_expression_type(self, t: RawExpressionType) -> None:
def visit_raw_expression_type(self, t: RawExpressionType, /) -> None:
pass

def visit_type_alias_type(self, t: TypeAliasType) -> None:
def visit_type_alias_type(self, t: TypeAliasType, /) -> None:
# TODO: sometimes we want to traverse target as well
# We need to find a way to indicate explicitly the intent,
# maybe make this method abstract (like for TypeTranslator)?
self.traverse_types(t.args)

def visit_unpack_type(self, t: UnpackType) -> None:
def visit_unpack_type(self, t: UnpackType, /) -> None:
t.type.accept(self)

# Helpers

def traverse_types(self, types: Iterable[Type]) -> None:
def traverse_types(self, types: Iterable[Type], /) -> None:
for typ in types:
typ.accept(self)
324 changes: 162 additions & 162 deletions mypy/visitor.py

Large diffs are not rendered by default.