From 9b6f29e8803e4c4284de497073786b41acc6d800 Mon Sep 17 00:00:00 2001 From: Shantanu Jain Date: Sat, 28 Dec 2024 18:15:30 -0800 Subject: [PATCH 1/2] Ensure LSP on arg names Pairs well with #18355 --- mypy/mixedtraverser.py | 32 ++-- mypy/plugin.py | 11 +- mypy/semanal.py | 2 +- mypy/semanal_shared.py | 15 +- mypy/test/data.py | 2 +- mypy/test/test_find_sources.py | 22 +-- mypy/traverser.py | 114 ++++++------ mypy/type_visitor.py | 52 +++--- mypy/typeanal.py | 8 +- mypy/typetraverser.py | 54 +++--- mypy/visitor.py | 324 ++++++++++++++++----------------- 11 files changed, 319 insertions(+), 317 deletions(-) diff --git a/mypy/mixedtraverser.py b/mypy/mixedtraverser.py index dfde41859c67..9fdc4457d18e 100644 --- a/mypy/mixedtraverser.py +++ b/mypy/mixedtraverser.py @@ -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) diff --git a/mypy/plugin.py b/mypy/plugin.py index fcbbc32f6237..4f1d4598094c 100644 --- a/mypy/plugin.py +++ b/mypy/plugin.py @@ -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,7 +341,7 @@ 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. @@ -348,7 +349,7 @@ def lookup_fully_qualified(self, name: 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: """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 diff --git a/mypy/semanal.py b/mypy/semanal.py index 6e3335aed4e1..ebe6a9312b96 100644 --- a/mypy/semanal.py +++ b/mypy/semanal.py @@ -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) diff --git a/mypy/semanal_shared.py b/mypy/semanal_shared.py index 941a16a7fd5d..4eb13d229433 100644 --- a/mypy/semanal_shared.py +++ b/mypy/semanal_shared.py @@ -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( diff --git a/mypy/test/data.py b/mypy/test/data.py index bc17178d20e0..bb30ab69a293 100644 --- a/mypy/test/data.py +++ b/mypy/test/data.py @@ -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 diff --git a/mypy/test/test_find_sources.py b/mypy/test/test_find_sources.py index 21ba0903a824..321f3405e999 100644 --- a/mypy/test/test_find_sources.py +++ b/mypy/test/test_find_sources.py @@ -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 diff --git a/mypy/traverser.py b/mypy/traverser.py index 9c333c587f7c..ab632064d9f9 100644 --- a/mypy/traverser.py +++ b/mypy/traverser.py @@ -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,52 +153,52 @@ 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: @@ -206,13 +206,13 @@ def visit_if_stmt(self, o: IfStmt) -> None: 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,7 +227,7 @@ 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] @@ -235,7 +235,7 @@ def visit_with_stmt(self, o: WithStmt) -> 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,38 +244,38 @@ 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: @@ -283,13 +283,13 @@ def visit_slice_expr(self, o: SliceExpr) -> None: 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) @@ -297,38 +297,38 @@ def visit_reveal_expr(self, o: RevealExpr) -> None: # 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) @@ -336,7 +336,7 @@ def visit_generator_expr(self, o: GeneratorExpr) -> None: 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,54 +345,54 @@ 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: @@ -400,18 +400,18 @@ def visit_mapping_pattern(self, o: MappingPattern) -> None: 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) diff --git a/mypy/type_visitor.py b/mypy/type_visitor.py index 8aac7e5c2bbd..e8a47dbaa592 100644 --- a/mypy/type_visitor.py +++ b/mypy/type_visitor.py @@ -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 diff --git a/mypy/typeanal.py b/mypy/typeanal.py index 751ed85ea6f3..71bc69baf423 100644 --- a/mypy/typeanal.py +++ b/mypy/typeanal.py @@ -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) @@ -1938,12 +1938,12 @@ def anal_var_defs(self, var_defs: Sequence[TypeVarLikeType]) -> list[TypeVarLike def named_type( self, - fully_qualified_name: str, + 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: diff --git a/mypy/typetraverser.py b/mypy/typetraverser.py index a28bbf422b61..e2333ae8aa6d 100644 --- a/mypy/typetraverser.py +++ b/mypy/typetraverser.py @@ -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) diff --git a/mypy/visitor.py b/mypy/visitor.py index 340e1af64e00..6613b6cbb144 100644 --- a/mypy/visitor.py +++ b/mypy/visitor.py @@ -20,179 +20,179 @@ @mypyc_attr(allow_interpreted_subclasses=True) class ExpressionVisitor(Generic[T]): @abstractmethod - def visit_int_expr(self, o: mypy.nodes.IntExpr) -> T: + def visit_int_expr(self, o: mypy.nodes.IntExpr, /) -> T: pass @abstractmethod - def visit_str_expr(self, o: mypy.nodes.StrExpr) -> T: + def visit_str_expr(self, o: mypy.nodes.StrExpr, /) -> T: pass @abstractmethod - def visit_bytes_expr(self, o: mypy.nodes.BytesExpr) -> T: + def visit_bytes_expr(self, o: mypy.nodes.BytesExpr, /) -> T: pass @abstractmethod - def visit_float_expr(self, o: mypy.nodes.FloatExpr) -> T: + def visit_float_expr(self, o: mypy.nodes.FloatExpr, /) -> T: pass @abstractmethod - def visit_complex_expr(self, o: mypy.nodes.ComplexExpr) -> T: + def visit_complex_expr(self, o: mypy.nodes.ComplexExpr, /) -> T: pass @abstractmethod - def visit_ellipsis(self, o: mypy.nodes.EllipsisExpr) -> T: + def visit_ellipsis(self, o: mypy.nodes.EllipsisExpr, /) -> T: pass @abstractmethod - def visit_star_expr(self, o: mypy.nodes.StarExpr) -> T: + def visit_star_expr(self, o: mypy.nodes.StarExpr, /) -> T: pass @abstractmethod - def visit_name_expr(self, o: mypy.nodes.NameExpr) -> T: + def visit_name_expr(self, o: mypy.nodes.NameExpr, /) -> T: pass @abstractmethod - def visit_member_expr(self, o: mypy.nodes.MemberExpr) -> T: + def visit_member_expr(self, o: mypy.nodes.MemberExpr, /) -> T: pass @abstractmethod - def visit_yield_from_expr(self, o: mypy.nodes.YieldFromExpr) -> T: + def visit_yield_from_expr(self, o: mypy.nodes.YieldFromExpr, /) -> T: pass @abstractmethod - def visit_yield_expr(self, o: mypy.nodes.YieldExpr) -> T: + def visit_yield_expr(self, o: mypy.nodes.YieldExpr, /) -> T: pass @abstractmethod - def visit_call_expr(self, o: mypy.nodes.CallExpr) -> T: + def visit_call_expr(self, o: mypy.nodes.CallExpr, /) -> T: pass @abstractmethod - def visit_op_expr(self, o: mypy.nodes.OpExpr) -> T: + def visit_op_expr(self, o: mypy.nodes.OpExpr, /) -> T: pass @abstractmethod - def visit_comparison_expr(self, o: mypy.nodes.ComparisonExpr) -> T: + def visit_comparison_expr(self, o: mypy.nodes.ComparisonExpr, /) -> T: pass @abstractmethod - def visit_cast_expr(self, o: mypy.nodes.CastExpr) -> T: + def visit_cast_expr(self, o: mypy.nodes.CastExpr, /) -> T: pass @abstractmethod - def visit_assert_type_expr(self, o: mypy.nodes.AssertTypeExpr) -> T: + def visit_assert_type_expr(self, o: mypy.nodes.AssertTypeExpr, /) -> T: pass @abstractmethod - def visit_reveal_expr(self, o: mypy.nodes.RevealExpr) -> T: + def visit_reveal_expr(self, o: mypy.nodes.RevealExpr, /) -> T: pass @abstractmethod - def visit_super_expr(self, o: mypy.nodes.SuperExpr) -> T: + def visit_super_expr(self, o: mypy.nodes.SuperExpr, /) -> T: pass @abstractmethod - def visit_unary_expr(self, o: mypy.nodes.UnaryExpr) -> T: + def visit_unary_expr(self, o: mypy.nodes.UnaryExpr, /) -> T: pass @abstractmethod - def visit_assignment_expr(self, o: mypy.nodes.AssignmentExpr) -> T: + def visit_assignment_expr(self, o: mypy.nodes.AssignmentExpr, /) -> T: pass @abstractmethod - def visit_list_expr(self, o: mypy.nodes.ListExpr) -> T: + def visit_list_expr(self, o: mypy.nodes.ListExpr, /) -> T: pass @abstractmethod - def visit_dict_expr(self, o: mypy.nodes.DictExpr) -> T: + def visit_dict_expr(self, o: mypy.nodes.DictExpr, /) -> T: pass @abstractmethod - def visit_tuple_expr(self, o: mypy.nodes.TupleExpr) -> T: + def visit_tuple_expr(self, o: mypy.nodes.TupleExpr, /) -> T: pass @abstractmethod - def visit_set_expr(self, o: mypy.nodes.SetExpr) -> T: + def visit_set_expr(self, o: mypy.nodes.SetExpr, /) -> T: pass @abstractmethod - def visit_index_expr(self, o: mypy.nodes.IndexExpr) -> T: + def visit_index_expr(self, o: mypy.nodes.IndexExpr, /) -> T: pass @abstractmethod - def visit_type_application(self, o: mypy.nodes.TypeApplication) -> T: + def visit_type_application(self, o: mypy.nodes.TypeApplication, /) -> T: pass @abstractmethod - def visit_lambda_expr(self, o: mypy.nodes.LambdaExpr) -> T: + def visit_lambda_expr(self, o: mypy.nodes.LambdaExpr, /) -> T: pass @abstractmethod - def visit_list_comprehension(self, o: mypy.nodes.ListComprehension) -> T: + def visit_list_comprehension(self, o: mypy.nodes.ListComprehension, /) -> T: pass @abstractmethod - def visit_set_comprehension(self, o: mypy.nodes.SetComprehension) -> T: + def visit_set_comprehension(self, o: mypy.nodes.SetComprehension, /) -> T: pass @abstractmethod - def visit_dictionary_comprehension(self, o: mypy.nodes.DictionaryComprehension) -> T: + def visit_dictionary_comprehension(self, o: mypy.nodes.DictionaryComprehension, /) -> T: pass @abstractmethod - def visit_generator_expr(self, o: mypy.nodes.GeneratorExpr) -> T: + def visit_generator_expr(self, o: mypy.nodes.GeneratorExpr, /) -> T: pass @abstractmethod - def visit_slice_expr(self, o: mypy.nodes.SliceExpr) -> T: + def visit_slice_expr(self, o: mypy.nodes.SliceExpr, /) -> T: pass @abstractmethod - def visit_conditional_expr(self, o: mypy.nodes.ConditionalExpr) -> T: + def visit_conditional_expr(self, o: mypy.nodes.ConditionalExpr, /) -> T: pass @abstractmethod - def visit_type_var_expr(self, o: mypy.nodes.TypeVarExpr) -> T: + def visit_type_var_expr(self, o: mypy.nodes.TypeVarExpr, /) -> T: pass @abstractmethod - def visit_paramspec_expr(self, o: mypy.nodes.ParamSpecExpr) -> T: + def visit_paramspec_expr(self, o: mypy.nodes.ParamSpecExpr, /) -> T: pass @abstractmethod - def visit_type_var_tuple_expr(self, o: mypy.nodes.TypeVarTupleExpr) -> T: + def visit_type_var_tuple_expr(self, o: mypy.nodes.TypeVarTupleExpr, /) -> T: pass @abstractmethod - def visit_type_alias_expr(self, o: mypy.nodes.TypeAliasExpr) -> T: + def visit_type_alias_expr(self, o: mypy.nodes.TypeAliasExpr, /) -> T: pass @abstractmethod - def visit_namedtuple_expr(self, o: mypy.nodes.NamedTupleExpr) -> T: + def visit_namedtuple_expr(self, o: mypy.nodes.NamedTupleExpr, /) -> T: pass @abstractmethod - def visit_enum_call_expr(self, o: mypy.nodes.EnumCallExpr) -> T: + def visit_enum_call_expr(self, o: mypy.nodes.EnumCallExpr, /) -> T: pass @abstractmethod - def visit_typeddict_expr(self, o: mypy.nodes.TypedDictExpr) -> T: + def visit_typeddict_expr(self, o: mypy.nodes.TypedDictExpr, /) -> T: pass @abstractmethod - def visit_newtype_expr(self, o: mypy.nodes.NewTypeExpr) -> T: + def visit_newtype_expr(self, o: mypy.nodes.NewTypeExpr, /) -> T: pass @abstractmethod - def visit__promote_expr(self, o: mypy.nodes.PromoteExpr) -> T: + def visit__promote_expr(self, o: mypy.nodes.PromoteExpr, /) -> T: pass @abstractmethod - def visit_await_expr(self, o: mypy.nodes.AwaitExpr) -> T: + def visit_await_expr(self, o: mypy.nodes.AwaitExpr, /) -> T: pass @abstractmethod - def visit_temp_node(self, o: mypy.nodes.TempNode) -> T: + def visit_temp_node(self, o: mypy.nodes.TempNode, /) -> T: pass @@ -202,115 +202,115 @@ class StatementVisitor(Generic[T]): # Definitions @abstractmethod - def visit_assignment_stmt(self, o: mypy.nodes.AssignmentStmt) -> T: + def visit_assignment_stmt(self, o: mypy.nodes.AssignmentStmt, /) -> T: pass @abstractmethod - def visit_for_stmt(self, o: mypy.nodes.ForStmt) -> T: + def visit_for_stmt(self, o: mypy.nodes.ForStmt, /) -> T: pass @abstractmethod - def visit_with_stmt(self, o: mypy.nodes.WithStmt) -> T: + def visit_with_stmt(self, o: mypy.nodes.WithStmt, /) -> T: pass @abstractmethod - def visit_del_stmt(self, o: mypy.nodes.DelStmt) -> T: + def visit_del_stmt(self, o: mypy.nodes.DelStmt, /) -> T: pass @abstractmethod - def visit_func_def(self, o: mypy.nodes.FuncDef) -> T: + def visit_func_def(self, o: mypy.nodes.FuncDef, /) -> T: pass @abstractmethod - def visit_overloaded_func_def(self, o: mypy.nodes.OverloadedFuncDef) -> T: + def visit_overloaded_func_def(self, o: mypy.nodes.OverloadedFuncDef, /) -> T: pass @abstractmethod - def visit_class_def(self, o: mypy.nodes.ClassDef) -> T: + def visit_class_def(self, o: mypy.nodes.ClassDef, /) -> T: pass @abstractmethod - def visit_global_decl(self, o: mypy.nodes.GlobalDecl) -> T: + def visit_global_decl(self, o: mypy.nodes.GlobalDecl, /) -> T: pass @abstractmethod - def visit_nonlocal_decl(self, o: mypy.nodes.NonlocalDecl) -> T: + def visit_nonlocal_decl(self, o: mypy.nodes.NonlocalDecl, /) -> T: pass @abstractmethod - def visit_decorator(self, o: mypy.nodes.Decorator) -> T: + def visit_decorator(self, o: mypy.nodes.Decorator, /) -> T: pass # Module structure @abstractmethod - def visit_import(self, o: mypy.nodes.Import) -> T: + def visit_import(self, o: mypy.nodes.Import, /) -> T: pass @abstractmethod - def visit_import_from(self, o: mypy.nodes.ImportFrom) -> T: + def visit_import_from(self, o: mypy.nodes.ImportFrom, /) -> T: pass @abstractmethod - def visit_import_all(self, o: mypy.nodes.ImportAll) -> T: + def visit_import_all(self, o: mypy.nodes.ImportAll, /) -> T: pass # Statements @abstractmethod - def visit_block(self, o: mypy.nodes.Block) -> T: + def visit_block(self, o: mypy.nodes.Block, /) -> T: pass @abstractmethod - def visit_expression_stmt(self, o: mypy.nodes.ExpressionStmt) -> T: + def visit_expression_stmt(self, o: mypy.nodes.ExpressionStmt, /) -> T: pass @abstractmethod - def visit_operator_assignment_stmt(self, o: mypy.nodes.OperatorAssignmentStmt) -> T: + def visit_operator_assignment_stmt(self, o: mypy.nodes.OperatorAssignmentStmt, /) -> T: pass @abstractmethod - def visit_while_stmt(self, o: mypy.nodes.WhileStmt) -> T: + def visit_while_stmt(self, o: mypy.nodes.WhileStmt, /) -> T: pass @abstractmethod - def visit_return_stmt(self, o: mypy.nodes.ReturnStmt) -> T: + def visit_return_stmt(self, o: mypy.nodes.ReturnStmt, /) -> T: pass @abstractmethod - def visit_assert_stmt(self, o: mypy.nodes.AssertStmt) -> T: + def visit_assert_stmt(self, o: mypy.nodes.AssertStmt, /) -> T: pass @abstractmethod - def visit_if_stmt(self, o: mypy.nodes.IfStmt) -> T: + def visit_if_stmt(self, o: mypy.nodes.IfStmt, /) -> T: pass @abstractmethod - def visit_break_stmt(self, o: mypy.nodes.BreakStmt) -> T: + def visit_break_stmt(self, o: mypy.nodes.BreakStmt, /) -> T: pass @abstractmethod - def visit_continue_stmt(self, o: mypy.nodes.ContinueStmt) -> T: + def visit_continue_stmt(self, o: mypy.nodes.ContinueStmt, /) -> T: pass @abstractmethod - def visit_pass_stmt(self, o: mypy.nodes.PassStmt) -> T: + def visit_pass_stmt(self, o: mypy.nodes.PassStmt, /) -> T: pass @abstractmethod - def visit_raise_stmt(self, o: mypy.nodes.RaiseStmt) -> T: + def visit_raise_stmt(self, o: mypy.nodes.RaiseStmt, /) -> T: pass @abstractmethod - def visit_try_stmt(self, o: mypy.nodes.TryStmt) -> T: + def visit_try_stmt(self, o: mypy.nodes.TryStmt, /) -> T: pass @abstractmethod - def visit_match_stmt(self, o: mypy.nodes.MatchStmt) -> T: + def visit_match_stmt(self, o: mypy.nodes.MatchStmt, /) -> T: pass @abstractmethod - def visit_type_alias_stmt(self, o: mypy.nodes.TypeAliasStmt) -> T: + def visit_type_alias_stmt(self, o: mypy.nodes.TypeAliasStmt, /) -> T: pass @@ -318,35 +318,35 @@ def visit_type_alias_stmt(self, o: mypy.nodes.TypeAliasStmt) -> T: @mypyc_attr(allow_interpreted_subclasses=True) class PatternVisitor(Generic[T]): @abstractmethod - def visit_as_pattern(self, o: mypy.patterns.AsPattern) -> T: + def visit_as_pattern(self, o: mypy.patterns.AsPattern, /) -> T: pass @abstractmethod - def visit_or_pattern(self, o: mypy.patterns.OrPattern) -> T: + def visit_or_pattern(self, o: mypy.patterns.OrPattern, /) -> T: pass @abstractmethod - def visit_value_pattern(self, o: mypy.patterns.ValuePattern) -> T: + def visit_value_pattern(self, o: mypy.patterns.ValuePattern, /) -> T: pass @abstractmethod - def visit_singleton_pattern(self, o: mypy.patterns.SingletonPattern) -> T: + def visit_singleton_pattern(self, o: mypy.patterns.SingletonPattern, /) -> T: pass @abstractmethod - def visit_sequence_pattern(self, o: mypy.patterns.SequencePattern) -> T: + def visit_sequence_pattern(self, o: mypy.patterns.SequencePattern, /) -> T: pass @abstractmethod - def visit_starred_pattern(self, o: mypy.patterns.StarredPattern) -> T: + def visit_starred_pattern(self, o: mypy.patterns.StarredPattern, /) -> T: pass @abstractmethod - def visit_mapping_pattern(self, o: mypy.patterns.MappingPattern) -> T: + def visit_mapping_pattern(self, o: mypy.patterns.MappingPattern, /) -> T: pass @abstractmethod - def visit_class_pattern(self, o: mypy.patterns.ClassPattern) -> T: + def visit_class_pattern(self, o: mypy.patterns.ClassPattern, /) -> T: pass @@ -365,264 +365,264 @@ class NodeVisitor(Generic[T], ExpressionVisitor[T], StatementVisitor[T], Pattern # Not in superclasses: - def visit_mypy_file(self, o: mypy.nodes.MypyFile) -> T: + def visit_mypy_file(self, o: mypy.nodes.MypyFile, /) -> T: pass # TODO: We have a visit_var method, but no visit_typeinfo or any # other non-Statement SymbolNode (accepting those will raise a # runtime error). Maybe this should be resolved in some direction. - def visit_var(self, o: mypy.nodes.Var) -> T: + def visit_var(self, o: mypy.nodes.Var, /) -> T: pass # Module structure - def visit_import(self, o: mypy.nodes.Import) -> T: + def visit_import(self, o: mypy.nodes.Import, /) -> T: pass - def visit_import_from(self, o: mypy.nodes.ImportFrom) -> T: + def visit_import_from(self, o: mypy.nodes.ImportFrom, /) -> T: pass - def visit_import_all(self, o: mypy.nodes.ImportAll) -> T: + def visit_import_all(self, o: mypy.nodes.ImportAll, /) -> T: pass # Definitions - def visit_func_def(self, o: mypy.nodes.FuncDef) -> T: + def visit_func_def(self, o: mypy.nodes.FuncDef, /) -> T: pass - def visit_overloaded_func_def(self, o: mypy.nodes.OverloadedFuncDef) -> T: + def visit_overloaded_func_def(self, o: mypy.nodes.OverloadedFuncDef, /) -> T: pass - def visit_class_def(self, o: mypy.nodes.ClassDef) -> T: + def visit_class_def(self, o: mypy.nodes.ClassDef, /) -> T: pass - def visit_global_decl(self, o: mypy.nodes.GlobalDecl) -> T: + def visit_global_decl(self, o: mypy.nodes.GlobalDecl, /) -> T: pass - def visit_nonlocal_decl(self, o: mypy.nodes.NonlocalDecl) -> T: + def visit_nonlocal_decl(self, o: mypy.nodes.NonlocalDecl, /) -> T: pass - def visit_decorator(self, o: mypy.nodes.Decorator) -> T: + def visit_decorator(self, o: mypy.nodes.Decorator, /) -> T: pass - def visit_type_alias(self, o: mypy.nodes.TypeAlias) -> T: + def visit_type_alias(self, o: mypy.nodes.TypeAlias, /) -> T: pass - def visit_placeholder_node(self, o: mypy.nodes.PlaceholderNode) -> T: + def visit_placeholder_node(self, o: mypy.nodes.PlaceholderNode, /) -> T: pass # Statements - def visit_block(self, o: mypy.nodes.Block) -> T: + def visit_block(self, o: mypy.nodes.Block, /) -> T: pass - def visit_expression_stmt(self, o: mypy.nodes.ExpressionStmt) -> T: + def visit_expression_stmt(self, o: mypy.nodes.ExpressionStmt, /) -> T: pass - def visit_assignment_stmt(self, o: mypy.nodes.AssignmentStmt) -> T: + def visit_assignment_stmt(self, o: mypy.nodes.AssignmentStmt, /) -> T: pass - def visit_operator_assignment_stmt(self, o: mypy.nodes.OperatorAssignmentStmt) -> T: + def visit_operator_assignment_stmt(self, o: mypy.nodes.OperatorAssignmentStmt, /) -> T: pass - def visit_while_stmt(self, o: mypy.nodes.WhileStmt) -> T: + def visit_while_stmt(self, o: mypy.nodes.WhileStmt, /) -> T: pass - def visit_for_stmt(self, o: mypy.nodes.ForStmt) -> T: + def visit_for_stmt(self, o: mypy.nodes.ForStmt, /) -> T: pass - def visit_return_stmt(self, o: mypy.nodes.ReturnStmt) -> T: + def visit_return_stmt(self, o: mypy.nodes.ReturnStmt, /) -> T: pass - def visit_assert_stmt(self, o: mypy.nodes.AssertStmt) -> T: + def visit_assert_stmt(self, o: mypy.nodes.AssertStmt, /) -> T: pass - def visit_del_stmt(self, o: mypy.nodes.DelStmt) -> T: + def visit_del_stmt(self, o: mypy.nodes.DelStmt, /) -> T: pass - def visit_if_stmt(self, o: mypy.nodes.IfStmt) -> T: + def visit_if_stmt(self, o: mypy.nodes.IfStmt, /) -> T: pass - def visit_break_stmt(self, o: mypy.nodes.BreakStmt) -> T: + def visit_break_stmt(self, o: mypy.nodes.BreakStmt, /) -> T: pass - def visit_continue_stmt(self, o: mypy.nodes.ContinueStmt) -> T: + def visit_continue_stmt(self, o: mypy.nodes.ContinueStmt, /) -> T: pass - def visit_pass_stmt(self, o: mypy.nodes.PassStmt) -> T: + def visit_pass_stmt(self, o: mypy.nodes.PassStmt, /) -> T: pass - def visit_raise_stmt(self, o: mypy.nodes.RaiseStmt) -> T: + def visit_raise_stmt(self, o: mypy.nodes.RaiseStmt, /) -> T: pass - def visit_try_stmt(self, o: mypy.nodes.TryStmt) -> T: + def visit_try_stmt(self, o: mypy.nodes.TryStmt, /) -> T: pass - def visit_with_stmt(self, o: mypy.nodes.WithStmt) -> T: + def visit_with_stmt(self, o: mypy.nodes.WithStmt, /) -> T: pass - def visit_match_stmt(self, o: mypy.nodes.MatchStmt) -> T: + def visit_match_stmt(self, o: mypy.nodes.MatchStmt, /) -> T: pass - def visit_type_alias_stmt(self, o: mypy.nodes.TypeAliasStmt) -> T: + def visit_type_alias_stmt(self, o: mypy.nodes.TypeAliasStmt, /) -> T: pass # Expressions (default no-op implementation) - def visit_int_expr(self, o: mypy.nodes.IntExpr) -> T: + def visit_int_expr(self, o: mypy.nodes.IntExpr, /) -> T: pass - def visit_str_expr(self, o: mypy.nodes.StrExpr) -> T: + def visit_str_expr(self, o: mypy.nodes.StrExpr, /) -> T: pass - def visit_bytes_expr(self, o: mypy.nodes.BytesExpr) -> T: + def visit_bytes_expr(self, o: mypy.nodes.BytesExpr, /) -> T: pass - def visit_float_expr(self, o: mypy.nodes.FloatExpr) -> T: + def visit_float_expr(self, o: mypy.nodes.FloatExpr, /) -> T: pass - def visit_complex_expr(self, o: mypy.nodes.ComplexExpr) -> T: + def visit_complex_expr(self, o: mypy.nodes.ComplexExpr, /) -> T: pass - def visit_ellipsis(self, o: mypy.nodes.EllipsisExpr) -> T: + def visit_ellipsis(self, o: mypy.nodes.EllipsisExpr, /) -> T: pass - def visit_star_expr(self, o: mypy.nodes.StarExpr) -> T: + def visit_star_expr(self, o: mypy.nodes.StarExpr, /) -> T: pass - def visit_name_expr(self, o: mypy.nodes.NameExpr) -> T: + def visit_name_expr(self, o: mypy.nodes.NameExpr, /) -> T: pass - def visit_member_expr(self, o: mypy.nodes.MemberExpr) -> T: + def visit_member_expr(self, o: mypy.nodes.MemberExpr, /) -> T: pass - def visit_yield_from_expr(self, o: mypy.nodes.YieldFromExpr) -> T: + def visit_yield_from_expr(self, o: mypy.nodes.YieldFromExpr, /) -> T: pass - def visit_yield_expr(self, o: mypy.nodes.YieldExpr) -> T: + def visit_yield_expr(self, o: mypy.nodes.YieldExpr, /) -> T: pass - def visit_call_expr(self, o: mypy.nodes.CallExpr) -> T: + def visit_call_expr(self, o: mypy.nodes.CallExpr, /) -> T: pass - def visit_op_expr(self, o: mypy.nodes.OpExpr) -> T: + def visit_op_expr(self, o: mypy.nodes.OpExpr, /) -> T: pass - def visit_comparison_expr(self, o: mypy.nodes.ComparisonExpr) -> T: + def visit_comparison_expr(self, o: mypy.nodes.ComparisonExpr, /) -> T: pass - def visit_cast_expr(self, o: mypy.nodes.CastExpr) -> T: + def visit_cast_expr(self, o: mypy.nodes.CastExpr, /) -> T: pass - def visit_assert_type_expr(self, o: mypy.nodes.AssertTypeExpr) -> T: + def visit_assert_type_expr(self, o: mypy.nodes.AssertTypeExpr, /) -> T: pass - def visit_reveal_expr(self, o: mypy.nodes.RevealExpr) -> T: + def visit_reveal_expr(self, o: mypy.nodes.RevealExpr, /) -> T: pass - def visit_super_expr(self, o: mypy.nodes.SuperExpr) -> T: + def visit_super_expr(self, o: mypy.nodes.SuperExpr, /) -> T: pass - def visit_assignment_expr(self, o: mypy.nodes.AssignmentExpr) -> T: + def visit_assignment_expr(self, o: mypy.nodes.AssignmentExpr, /) -> T: pass - def visit_unary_expr(self, o: mypy.nodes.UnaryExpr) -> T: + def visit_unary_expr(self, o: mypy.nodes.UnaryExpr, /) -> T: pass - def visit_list_expr(self, o: mypy.nodes.ListExpr) -> T: + def visit_list_expr(self, o: mypy.nodes.ListExpr, /) -> T: pass - def visit_dict_expr(self, o: mypy.nodes.DictExpr) -> T: + def visit_dict_expr(self, o: mypy.nodes.DictExpr, /) -> T: pass - def visit_tuple_expr(self, o: mypy.nodes.TupleExpr) -> T: + def visit_tuple_expr(self, o: mypy.nodes.TupleExpr, /) -> T: pass - def visit_set_expr(self, o: mypy.nodes.SetExpr) -> T: + def visit_set_expr(self, o: mypy.nodes.SetExpr, /) -> T: pass - def visit_index_expr(self, o: mypy.nodes.IndexExpr) -> T: + def visit_index_expr(self, o: mypy.nodes.IndexExpr, /) -> T: pass - def visit_type_application(self, o: mypy.nodes.TypeApplication) -> T: + def visit_type_application(self, o: mypy.nodes.TypeApplication, /) -> T: pass - def visit_lambda_expr(self, o: mypy.nodes.LambdaExpr) -> T: + def visit_lambda_expr(self, o: mypy.nodes.LambdaExpr, /) -> T: pass - def visit_list_comprehension(self, o: mypy.nodes.ListComprehension) -> T: + def visit_list_comprehension(self, o: mypy.nodes.ListComprehension, /) -> T: pass - def visit_set_comprehension(self, o: mypy.nodes.SetComprehension) -> T: + def visit_set_comprehension(self, o: mypy.nodes.SetComprehension, /) -> T: pass - def visit_dictionary_comprehension(self, o: mypy.nodes.DictionaryComprehension) -> T: + def visit_dictionary_comprehension(self, o: mypy.nodes.DictionaryComprehension, /) -> T: pass - def visit_generator_expr(self, o: mypy.nodes.GeneratorExpr) -> T: + def visit_generator_expr(self, o: mypy.nodes.GeneratorExpr, /) -> T: pass - def visit_slice_expr(self, o: mypy.nodes.SliceExpr) -> T: + def visit_slice_expr(self, o: mypy.nodes.SliceExpr, /) -> T: pass - def visit_conditional_expr(self, o: mypy.nodes.ConditionalExpr) -> T: + def visit_conditional_expr(self, o: mypy.nodes.ConditionalExpr, /) -> T: pass - def visit_type_var_expr(self, o: mypy.nodes.TypeVarExpr) -> T: + def visit_type_var_expr(self, o: mypy.nodes.TypeVarExpr, /) -> T: pass - def visit_paramspec_expr(self, o: mypy.nodes.ParamSpecExpr) -> T: + def visit_paramspec_expr(self, o: mypy.nodes.ParamSpecExpr, /) -> T: pass - def visit_type_var_tuple_expr(self, o: mypy.nodes.TypeVarTupleExpr) -> T: + def visit_type_var_tuple_expr(self, o: mypy.nodes.TypeVarTupleExpr, /) -> T: pass - def visit_type_alias_expr(self, o: mypy.nodes.TypeAliasExpr) -> T: + def visit_type_alias_expr(self, o: mypy.nodes.TypeAliasExpr, /) -> T: pass - def visit_namedtuple_expr(self, o: mypy.nodes.NamedTupleExpr) -> T: + def visit_namedtuple_expr(self, o: mypy.nodes.NamedTupleExpr, /) -> T: pass - def visit_enum_call_expr(self, o: mypy.nodes.EnumCallExpr) -> T: + def visit_enum_call_expr(self, o: mypy.nodes.EnumCallExpr, /) -> T: pass - def visit_typeddict_expr(self, o: mypy.nodes.TypedDictExpr) -> T: + def visit_typeddict_expr(self, o: mypy.nodes.TypedDictExpr, /) -> T: pass - def visit_newtype_expr(self, o: mypy.nodes.NewTypeExpr) -> T: + def visit_newtype_expr(self, o: mypy.nodes.NewTypeExpr, /) -> T: pass - def visit__promote_expr(self, o: mypy.nodes.PromoteExpr) -> T: + def visit__promote_expr(self, o: mypy.nodes.PromoteExpr, /) -> T: pass - def visit_await_expr(self, o: mypy.nodes.AwaitExpr) -> T: + def visit_await_expr(self, o: mypy.nodes.AwaitExpr, /) -> T: pass - def visit_temp_node(self, o: mypy.nodes.TempNode) -> T: + def visit_temp_node(self, o: mypy.nodes.TempNode, /) -> T: pass # Patterns - def visit_as_pattern(self, o: mypy.patterns.AsPattern) -> T: + def visit_as_pattern(self, o: mypy.patterns.AsPattern, /) -> T: pass - def visit_or_pattern(self, o: mypy.patterns.OrPattern) -> T: + def visit_or_pattern(self, o: mypy.patterns.OrPattern, /) -> T: pass - def visit_value_pattern(self, o: mypy.patterns.ValuePattern) -> T: + def visit_value_pattern(self, o: mypy.patterns.ValuePattern, /) -> T: pass - def visit_singleton_pattern(self, o: mypy.patterns.SingletonPattern) -> T: + def visit_singleton_pattern(self, o: mypy.patterns.SingletonPattern, /) -> T: pass - def visit_sequence_pattern(self, o: mypy.patterns.SequencePattern) -> T: + def visit_sequence_pattern(self, o: mypy.patterns.SequencePattern, /) -> T: pass - def visit_starred_pattern(self, o: mypy.patterns.StarredPattern) -> T: + def visit_starred_pattern(self, o: mypy.patterns.StarredPattern, /) -> T: pass - def visit_mapping_pattern(self, o: mypy.patterns.MappingPattern) -> T: + def visit_mapping_pattern(self, o: mypy.patterns.MappingPattern, /) -> T: pass - def visit_class_pattern(self, o: mypy.patterns.ClassPattern) -> T: + def visit_class_pattern(self, o: mypy.patterns.ClassPattern, /) -> T: pass From 07c5813c5a2b2fecaf50957fe3dda94ed78080a3 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 29 Dec 2024 02:16:25 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mypy/typeanal.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/mypy/typeanal.py b/mypy/typeanal.py index 71bc69baf423..9d90ffe89932 100644 --- a/mypy/typeanal.py +++ b/mypy/typeanal.py @@ -1937,11 +1937,7 @@ 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, - 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(name) assert isinstance(node.node, TypeInfo)