Skip to content

Commit

Permalink
Make visit method arguments pos-only (#18361)
Browse files Browse the repository at this point in the history
Extracted from #18356. Make `visit_*` method arguments positional only
to ensure better LSP compatibility. Also update some visitors which
don't have violations yet but are base classes for other ones, like
`TypeTranslator` and `TypeQuery`.
  • Loading branch information
cdce8p authored Dec 29, 2024
1 parent d79d89e commit 9463929
Show file tree
Hide file tree
Showing 7 changed files with 477 additions and 477 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)
Loading

0 comments on commit 9463929

Please sign in to comment.