diff --git a/source/analysis/analysisError.ml b/source/analysis/analysisError.ml index 3850f0271cf..dcba40e5724 100644 --- a/source/analysis/analysisError.ml +++ b/source/analysis/analysisError.ml @@ -1791,9 +1791,7 @@ let rec messages ~concise ~signature location kind = let arguments = if has_arguments then "(...)" else "" in let recurse = messages ~concise ~signature location in let has_param_spec_variable = function - | Type.Callable { implementation = { parameters = ParameterVariadicTypeVariable _; _ }; _ } - -> - true + | Type.Callable { implementation = { parameters = FromParamSpec _; _ }; _ } -> true | _ -> false in match reason, reason >>| recurse >>= List.hd with @@ -2490,8 +2488,7 @@ let rec messages ~concise ~signature location kind = "See https://pyre-check.org/docs/errors/#62-non-literal-string for more details."; ] | NotCallable - (Type.Callable { implementation = { parameters = ParameterVariadicTypeVariable _; _ }; _ } as - annotation) -> + (Type.Callable { implementation = { parameters = FromParamSpec _; _ }; _ } as annotation) -> [ Format.asprintf "`%a` cannot be safely called because the types and kinds of its parameters depend on a \ diff --git a/source/analysis/annotatedCallable.ml b/source/analysis/annotatedCallable.ml index 19394fd6e4d..f7522d76d08 100644 --- a/source/analysis/annotatedCallable.ml +++ b/source/analysis/annotatedCallable.ml @@ -111,7 +111,7 @@ let create_overload_without_applying_decorators |> Option.all in match parsed_head with - | Some head -> ParameterVariadicTypeVariable { head; variable } + | Some head -> FromParamSpec { head; variable } | None -> default ()) | None -> default ()) | _ -> Defined (List.map parameters ~f:parse) diff --git a/source/analysis/annotatedDefine.ml b/source/analysis/annotatedDefine.ml index 18075a52f38..f0fad7a8fdd 100644 --- a/source/analysis/annotatedDefine.ml +++ b/source/analysis/annotatedDefine.ml @@ -115,7 +115,7 @@ let decorate placed_single_star, new_parameter :: sofar in List.fold parameters ~f:convert ~init:(false, []) |> snd |> List.rev - | ParameterVariadicTypeVariable _ + | FromParamSpec _ | Undefined -> original_parameters in diff --git a/source/analysis/attributeResolution.ml b/source/analysis/attributeResolution.ml index 51b1baaf5d7..e67cdc0f157 100644 --- a/source/analysis/attributeResolution.ml +++ b/source/analysis/attributeResolution.ml @@ -1307,8 +1307,7 @@ module SignatureSelection = struct |> check_arguments_against_parameters ~callable |> fun signature_match -> [signature_match] | Undefined -> [base_signature_match] - | ParameterVariadicTypeVariable { head; variable } when Type.Variable.ParamSpec.is_free variable - -> ( + | FromParamSpec { head; variable } when Type.Variable.ParamSpec.is_free variable -> ( (* Handle callables where an early parameter binds a ParamSpec and later parameters expect the corresponding arguments. @@ -1379,7 +1378,7 @@ module SignatureSelection = struct |> function | [] -> [head_signature] | nonempty -> nonempty) - | ParameterVariadicTypeVariable { head; variable } -> ( + | FromParamSpec { head; variable } -> ( (* The ParamSpec variable `P` is in scope, so the only valid arguments are `*args` and `**kwargs` that have "type" `P.args` and `P.kwargs` respectively. If the ParamSpec has a `head` prefix of parameters, check for any prefix arguments. *) @@ -1405,7 +1404,7 @@ module SignatureSelection = struct [ { base_signature_match with - reasons = { arity = [CallingParameterVariadicTypeVariable]; annotation = [] }; + reasons = { arity = [CallingFromParamSpec]; annotation = [] }; }; ]) @@ -1448,7 +1447,7 @@ module SignatureSelection = struct | [], reason :: reasons -> let importance = function | AbstractClassInstantiation _ -> 1 - | CallingParameterVariadicTypeVariable -> 1 + | CallingFromParamSpec -> 1 | InvalidKeywordArgument _ -> 0 | InvalidVariableArgument _ -> 0 | Mismatches _ -> -1 @@ -2127,8 +2126,7 @@ let partial_apply_self { Type.Callable.implementation; overloads; _ } ~order ~se let parameters = match parameters with | Type.Callable.Defined (_ :: parameters) -> Type.Callable.Defined parameters - | ParameterVariadicTypeVariable { head = _ :: head; variable } -> - ParameterVariadicTypeVariable { head; variable } + | FromParamSpec { head = _ :: head; variable } -> FromParamSpec { head; variable } | _ -> parameters in { Type.Callable.annotation; parameters } diff --git a/source/analysis/constraintsSet.ml b/source/analysis/constraintsSet.ml index b858d3c9644..9e9f6ede10c 100644 --- a/source/analysis/constraintsSet.ml +++ b/source/analysis/constraintsSet.ml @@ -313,8 +313,8 @@ module Make (OrderedConstraints : OrderedConstraintsType) = struct the Python type system at the moment. *) | Defined _, Undefined -> [initial_constraints] | Undefined, Defined _ -> [initial_constraints] - | ( ParameterVariadicTypeVariable { head = left_head; variable = left_variable }, - ParameterVariadicTypeVariable { head = right_head; variable = right_variable } ) + | ( FromParamSpec { head = left_head; variable = left_variable }, + FromParamSpec { head = right_head; variable = right_variable } ) when Type.Variable.ParamSpec.is_free left_variable && Type.Variable.ParamSpec.is_free right_variable -> let add_parameter_specification_bounds constraints = @@ -323,14 +323,12 @@ module Make (OrderedConstraints : OrderedConstraintsType) = struct ~order ~pair: (Type.Variable.ParamSpecPair - ( right_variable, - ParameterVariadicTypeVariable { head = []; variable = left_variable } )) + (right_variable, FromParamSpec { head = []; variable = left_variable })) >>= OrderedConstraints.add_lower_bound ~order ~pair: (Type.Variable.ParamSpecPair - ( left_variable, - ParameterVariadicTypeVariable { head = []; variable = right_variable } )) + (left_variable, FromParamSpec { head = []; variable = right_variable })) |> Option.to_list in solve_ordered_types_less_or_equal @@ -339,23 +337,22 @@ module Make (OrderedConstraints : OrderedConstraintsType) = struct ~right:(Type.OrderedTypes.Concrete left_head) ~constraints:initial_constraints |> List.concat_map ~f:add_parameter_specification_bounds - | bound, ParameterVariadicTypeVariable { head = []; variable } - when Type.Variable.ParamSpec.is_free variable -> + | bound, FromParamSpec { head = []; variable } when Type.Variable.ParamSpec.is_free variable + -> let pair = Type.Variable.ParamSpecPair (variable, bound) in OrderedConstraints.add_upper_bound initial_constraints ~order ~pair |> Option.to_list - | bound, ParameterVariadicTypeVariable { head; variable } - when Type.Variable.ParamSpec.is_free variable -> + | bound, FromParamSpec { head; variable } when Type.Variable.ParamSpec.is_free variable -> let constraints, remainder = match bound with | Undefined -> [initial_constraints], Undefined - | ParameterVariadicTypeVariable { head = left_head; variable = left_variable } -> + | FromParamSpec { head = left_head; variable = left_variable } -> let paired, remainder = List.split_n left_head (List.length head) in ( solve_ordered_types_less_or_equal order ~left:(Type.OrderedTypes.Concrete paired) ~right:(Type.OrderedTypes.Concrete head) ~constraints:initial_constraints, - ParameterVariadicTypeVariable { head = remainder; variable = left_variable } ) + FromParamSpec { head = remainder; variable = left_variable } ) | Defined defined -> let paired, remainder = List.split_n defined (List.length head) in ( solve_parameters @@ -366,8 +363,8 @@ module Make (OrderedConstraints : OrderedConstraintsType) = struct in let pair = Type.Variable.ParamSpecPair (variable, remainder) in List.filter_map constraints ~f:(OrderedConstraints.add_upper_bound ~order ~pair) - | ParameterVariadicTypeVariable left, ParameterVariadicTypeVariable right - when Type.Callable.equal_parameter_variadic_type_variable Type.equal left right -> + | FromParamSpec left, FromParamSpec right + when Type.Callable.equal_params_from_param_spec Type.equal left right -> [initial_constraints] | _, _ -> impossible with @@ -1071,9 +1068,7 @@ module Make (OrderedConstraints : OrderedConstraintsType) = struct |> fun instantiated -> [Type.Parameter.Single instantiated] | ParamSpecVariable variable -> TypeConstraints.Solution.instantiate_single_param_spec solution variable - |> Option.value - ~default: - (Type.Callable.ParameterVariadicTypeVariable { head = []; variable }) + |> Option.value ~default:(Type.Callable.FromParamSpec { head = []; variable }) |> fun instantiated -> [Type.Parameter.CallableParameters instantiated] | TypeVarTupleVariable variadic -> TypeConstraints.Solution.instantiate_ordered_types diff --git a/source/analysis/signatureSelectionTypes.ml b/source/analysis/signatureSelectionTypes.ml index 6098d999fec..d3caaa07f3e 100644 --- a/source/analysis/signatureSelectionTypes.ml +++ b/source/analysis/signatureSelectionTypes.ml @@ -55,7 +55,7 @@ type reason = class_name: Reference.t; abstract_methods: string list; } - | CallingParameterVariadicTypeVariable + | CallingFromParamSpec | InvalidKeywordArgument of invalid_argument Node.t | InvalidVariableArgument of invalid_argument Node.t | Mismatches of mismatch_reason list diff --git a/source/analysis/test/annotatedSignatureTest.ml b/source/analysis/test/annotatedSignatureTest.ml index 613a41f1170..53bfc633299 100644 --- a/source/analysis/test/annotatedSignatureTest.ml +++ b/source/analysis/test/annotatedSignatureTest.ml @@ -924,7 +924,7 @@ let test_unresolved_select = { annotation = Type.integer; parameters = - ParameterVariadicTypeVariable + FromParamSpec { head = []; variable = @@ -937,7 +937,7 @@ let test_unresolved_select = (NotFound { closest_return_annotation = Type.integer; - reason = Some SignatureSelectionTypes.CallingParameterVariadicTypeVariable; + reason = Some SignatureSelectionTypes.CallingFromParamSpec; }); ] diff --git a/source/analysis/test/constraintsSetTest.ml b/source/analysis/test/constraintsSetTest.ml index 0e2b5e7f090..65fd92364ba 100644 --- a/source/analysis/test/constraintsSetTest.ml +++ b/source/analysis/test/constraintsSetTest.ml @@ -372,7 +372,7 @@ let make_assert_functions context = None else Some - (Type.Callable.ParameterVariadicTypeVariable + (Type.Callable.FromParamSpec { head = []; variable = Type.Variable.ParamSpec.mark_as_bound variable }) in let mark_tuple_variadic variable = diff --git a/source/analysis/test/globalResolutionTest.ml b/source/analysis/test/globalResolutionTest.ml index 652a3a6d662..3fc211210ee 100644 --- a/source/analysis/test/globalResolutionTest.ml +++ b/source/analysis/test/globalResolutionTest.ml @@ -1227,8 +1227,7 @@ let test_invalid_type_parameters context = "test.Foo" [ CallableParameters - (ParameterVariadicTypeVariable - { Type.Callable.head = []; variable = parameter_variadic }); + (FromParamSpec { Type.Callable.head = []; variable = parameter_variadic }); ]) ~expected_transformed_type: (Type.parametric diff --git a/source/analysis/test/typeConstraintsTest.ml b/source/analysis/test/typeConstraintsTest.ml index baefadc9d86..70af102652c 100644 --- a/source/analysis/test/typeConstraintsTest.ml +++ b/source/analysis/test/typeConstraintsTest.ml @@ -406,9 +406,7 @@ let test_multiple_variable_solution _ = assert_solution ~sequentially_applied_bounds: [ - `Lower - (ParamSpecPair - (parameters_a, Type.Callable.ParameterVariadicTypeVariable (empty_head parameters_b))); + `Lower (ParamSpecPair (parameters_a, Type.Callable.FromParamSpec (empty_head parameters_b))); `Lower (ParamSpecPair (parameters_b, empty_parameters)); ] (Some @@ -422,12 +420,8 @@ let test_multiple_variable_solution _ = assert_solution ~sequentially_applied_bounds: [ - `Lower - (ParamSpecPair - (parameters_a, Type.Callable.ParameterVariadicTypeVariable (empty_head parameters_b))); - `Lower - (ParamSpecPair - (parameters_b, Type.Callable.ParameterVariadicTypeVariable (empty_head parameters_a))); + `Lower (ParamSpecPair (parameters_a, Type.Callable.FromParamSpec (empty_head parameters_b))); + `Lower (ParamSpecPair (parameters_b, Type.Callable.FromParamSpec (empty_head parameters_a))); ] None; let parameters_with_unconstrained_a = @@ -461,7 +455,7 @@ let test_multiple_variable_solution _ = (TypeVarPair ( unconstrained_a, Type.Callable.create - ~parameters:(Type.Callable.ParameterVariadicTypeVariable (empty_head parameters_a)) + ~parameters:(Type.Callable.FromParamSpec (empty_head parameters_a)) ~annotation:Type.integer () )); ] @@ -625,18 +619,10 @@ let test_partial_solution _ = ~variables:[Type.Variable.ParamSpecVariable parameters_a] ~bounds: [ - `Lower - (ParamSpecPair - (parameters_a, Type.Callable.ParameterVariadicTypeVariable (empty_head parameters_b))); - `Lower - (ParamSpecPair - (parameters_b, Type.Callable.ParameterVariadicTypeVariable (empty_head parameters_a))); + `Lower (ParamSpecPair (parameters_a, Type.Callable.FromParamSpec (empty_head parameters_b))); + `Lower (ParamSpecPair (parameters_b, Type.Callable.FromParamSpec (empty_head parameters_a))); ] - (Some - [ - ParamSpecPair - (parameters_a, Type.Callable.ParameterVariadicTypeVariable (empty_head parameters_b)); - ]) + (Some [ParamSpecPair (parameters_a, Type.Callable.FromParamSpec (empty_head parameters_b))]) (Some []); (* Variadic tuples. *) @@ -719,7 +705,7 @@ let test_exists _ = let constraints_with_parameters_b = let pair = Type.Variable.ParamSpecPair - (parameters_a, Type.Callable.ParameterVariadicTypeVariable (empty_head parameters_b)) + (parameters_a, Type.Callable.FromParamSpec (empty_head parameters_b)) in DiamondOrderedConstraints.add_lower_bound TypeConstraints.empty ~order ~pair |> fun constraints_option -> Option.value_exn constraints_option diff --git a/source/analysis/test/typeTest.ml b/source/analysis/test/typeTest.ml index 4cccf0a1ce8..dbf132717bd 100644 --- a/source/analysis/test/typeTest.ml +++ b/source/analysis/test/typeTest.ml @@ -1622,14 +1622,14 @@ let test_is_resolved _ = assert_false (Type.Variable.all_variables_are_resolved (Type.Callable.create - ~parameters:(Type.Callable.ParameterVariadicTypeVariable (empty_head parameter_variadic)) + ~parameters:(Type.Callable.FromParamSpec (empty_head parameter_variadic)) ~annotation:Type.integer ())); let parameter_variadic = parameter_variadic |> Type.Variable.ParamSpec.mark_as_bound in assert_true (Type.Variable.all_variables_are_resolved (Type.Callable.create - ~parameters:(Type.Callable.ParameterVariadicTypeVariable (empty_head parameter_variadic)) + ~parameters:(Type.Callable.FromParamSpec (empty_head parameter_variadic)) ~annotation:Type.integer ())); () @@ -1821,7 +1821,7 @@ let test_variables _ = [Type.Variable.TypeVarVariable unary; Type.Variable.ParamSpecVariable parameter_variadic] (Type.Variable.all_free_variables (Type.Callable.create - ~parameters:(Type.Callable.ParameterVariadicTypeVariable (empty_head parameter_variadic)) + ~parameters:(Type.Callable.FromParamSpec (empty_head parameter_variadic)) ~annotation:(Type.Variable unary) ())); () @@ -2055,7 +2055,7 @@ let test_mark_all_variables_as_bound _ = let callable = let parameter_variadic = Type.Variable.ParamSpec.create "T" in Type.Callable.create - ~parameters:(Type.Callable.ParameterVariadicTypeVariable (empty_head parameter_variadic)) + ~parameters:(Type.Callable.FromParamSpec (empty_head parameter_variadic)) ~annotation:Type.integer () in @@ -2075,7 +2075,7 @@ let test_mark_all_variables_as_free _ = let callable = let parameter_variadic = Type.Variable.ParamSpec.create "T" in Type.Callable.create - ~parameters:(Type.Callable.ParameterVariadicTypeVariable (empty_head parameter_variadic)) + ~parameters:(Type.Callable.FromParamSpec (empty_head parameter_variadic)) ~annotation:Type.integer () |> Type.Variable.mark_all_variables_as_bound @@ -2106,7 +2106,7 @@ let test_namespace_all_free_variables _ = let free_variable_callable = let parameter_variadic = Type.Variable.ParamSpec.create "T" in Type.Callable.create - ~parameters:(Type.Callable.ParameterVariadicTypeVariable (empty_head parameter_variadic)) + ~parameters:(Type.Callable.FromParamSpec (empty_head parameter_variadic)) ~annotation:Type.integer () in @@ -2115,7 +2115,7 @@ let test_namespace_all_free_variables _ = Type.Variable.ParamSpec.create "T" |> Type.Variable.ParamSpec.mark_as_bound in Type.Callable.create - ~parameters:(Type.Callable.ParameterVariadicTypeVariable (empty_head parameter_variadic)) + ~parameters:(Type.Callable.FromParamSpec (empty_head parameter_variadic)) ~annotation:Type.integer () in @@ -2126,7 +2126,7 @@ let test_namespace_all_free_variables _ = Type.Variable.ParamSpec.create "T" |> Type.Variable.ParamSpec.namespace ~namespace in Type.Callable.create - ~parameters:(Type.Callable.ParameterVariadicTypeVariable (empty_head parameter_variadic)) + ~parameters:(Type.Callable.FromParamSpec (empty_head parameter_variadic)) ~annotation:Type.integer () in @@ -2159,7 +2159,7 @@ let test_mark_all_free_variables_as_escaped _ = let free_variable_callable = let parameter_variadic = Type.Variable.ParamSpec.create "T" in Type.Callable.create - ~parameters:(Type.Callable.ParameterVariadicTypeVariable (empty_head parameter_variadic)) + ~parameters:(Type.Callable.FromParamSpec (empty_head parameter_variadic)) ~annotation:Type.integer () in @@ -2168,7 +2168,7 @@ let test_mark_all_free_variables_as_escaped _ = Type.Variable.ParamSpec.create "T" |> Type.Variable.ParamSpec.mark_as_bound in Type.Callable.create - ~parameters:(Type.Callable.ParameterVariadicTypeVariable (empty_head parameter_variadic)) + ~parameters:(Type.Callable.FromParamSpec (empty_head parameter_variadic)) ~annotation:Type.integer () in @@ -2182,7 +2182,7 @@ let test_mark_all_free_variables_as_escaped _ = |> Type.Variable.ParamSpec.namespace ~namespace in Type.Callable.create - ~parameters:(Type.Callable.ParameterVariadicTypeVariable (empty_head parameter_variadic)) + ~parameters:(Type.Callable.FromParamSpec (empty_head parameter_variadic)) ~annotation:Type.integer () in @@ -2205,7 +2205,7 @@ let test_contains_escaped_free_variable _ = let free_variable_callable = let parameter_variadic = Type.Variable.ParamSpec.create "T" in Type.Callable.create - ~parameters:(Type.Callable.ParameterVariadicTypeVariable (empty_head parameter_variadic)) + ~parameters:(Type.Callable.FromParamSpec (empty_head parameter_variadic)) ~annotation:Type.integer () in @@ -2215,7 +2215,7 @@ let test_contains_escaped_free_variable _ = Type.Variable.ParamSpec.create "T" |> Type.Variable.ParamSpec.mark_as_escaped in Type.Callable.create - ~parameters:(Type.Callable.ParameterVariadicTypeVariable (empty_head parameter_variadic)) + ~parameters:(Type.Callable.FromParamSpec (empty_head parameter_variadic)) ~annotation:Type.integer () in @@ -2237,7 +2237,7 @@ let test_convert_all_escaped_free_variables_to_anys _ = let free_variable_callable = let parameter_variadic = Type.Variable.ParamSpec.create "T" in Type.Callable.create - ~parameters:(Type.Callable.ParameterVariadicTypeVariable (empty_head parameter_variadic)) + ~parameters:(Type.Callable.FromParamSpec (empty_head parameter_variadic)) ~annotation:Type.integer () in @@ -2249,7 +2249,7 @@ let test_convert_all_escaped_free_variables_to_anys _ = |> Type.Variable.ParamSpec.namespace ~namespace in Type.Callable.create - ~parameters:(Type.Callable.ParameterVariadicTypeVariable (empty_head parameter_variadic)) + ~parameters:(Type.Callable.FromParamSpec (empty_head parameter_variadic)) ~annotation:Type.integer () in @@ -2291,7 +2291,7 @@ let test_replace_all _ = let free_variable_callable = let parameter_variadic = Type.Variable.ParamSpec.create "T" in Type.Callable.create - ~parameters:(Type.Callable.ParameterVariadicTypeVariable (empty_head parameter_variadic)) + ~parameters:(Type.Callable.FromParamSpec (empty_head parameter_variadic)) ~annotation:Type.integer () in @@ -2490,7 +2490,7 @@ let test_collect_all _ = let free_variable_callable = let parameter_variadic = Type.Variable.ParamSpec.create "T" in Type.Callable.create - ~parameters:(Type.Callable.ParameterVariadicTypeVariable (empty_head parameter_variadic)) + ~parameters:(Type.Callable.FromParamSpec (empty_head parameter_variadic)) ~annotation:Type.integer () in @@ -3104,8 +3104,7 @@ let test_zip_variables_with_parameters _ = { variable_pair = Type.Variable.ParamSpecPair - ( parameter_variadic, - Type.Callable.ParameterVariadicTypeVariable (empty_head parameter_variadic) ); + (parameter_variadic, Type.Callable.FromParamSpec (empty_head parameter_variadic)); received_parameter = CallableParameters (Type.Variable.ParamSpec.self_reference parameter_variadic); }; @@ -3267,8 +3266,7 @@ let test_zip_variables_with_parameters _ = { variable_pair = Type.Variable.ParamSpecPair - ( parameter_variadic, - Type.Callable.ParameterVariadicTypeVariable (empty_head parameter_variadic) ); + (parameter_variadic, Type.Callable.FromParamSpec (empty_head parameter_variadic)); received_parameter = CallableParameters (Type.Variable.ParamSpec.self_reference parameter_variadic); }; @@ -3290,8 +3288,7 @@ let test_zip_variables_with_parameters _ = { variable_pair = Type.Variable.ParamSpecPair - ( parameter_variadic, - Type.Callable.ParameterVariadicTypeVariable (empty_head parameter_variadic) ); + (parameter_variadic, Type.Callable.FromParamSpec (empty_head parameter_variadic)); received_parameter = CallableParameters (Type.Variable.ParamSpec.self_reference parameter_variadic); }; diff --git a/source/analysis/type.ml b/source/analysis/type.ml index 51504e66a14..a494feaa34c 100644 --- a/source/analysis/type.ml +++ b/source/analysis/type.ml @@ -222,7 +222,11 @@ module Record = struct | Anonymous | Named of Reference.t - and 'annotation parameter_variadic_type_variable = { + (* This represents a callable whose parameter signature is determined by a ParamSpec. This could + be a callable whose parameters are *just* a ParamSpec (e.g. `Callable[P, R]`), or it could be + one whose parameters add one or more positional-only arguments preceding the param spec, e.g. + `Callable[Concatenate[T0, T1, P], R]`. *) + and 'annotation params_from_param_spec = { head: 'annotation list; variable: 'annotation Variable.ParamSpec.record; } @@ -230,7 +234,7 @@ module Record = struct and 'annotation record_parameters = | Defined of 'annotation CallableParamType.t list | Undefined - | ParameterVariadicTypeVariable of 'annotation parameter_variadic_type_variable + | FromParamSpec of 'annotation params_from_param_spec and 'annotation overload = { annotation: 'annotation; (* return type annotation *) @@ -545,9 +549,8 @@ module VisitWithTransform = struct in match parameter with | Defined defined -> Defined (List.map defined ~f:visit_defined) - | ParameterVariadicTypeVariable { head; variable } -> - ParameterVariadicTypeVariable - { head = List.map head ~f:(visit_annotation ~state); variable } + | FromParamSpec { head; variable } -> + FromParamSpec { head = List.map head ~f:(visit_annotation ~state); variable } | parameter -> parameter in match annotation with @@ -1176,7 +1179,7 @@ module PrettyPrinting = struct let show_callable_parameters ~pp_type = function | Record.Callable.Undefined -> "..." - | ParameterVariadicTypeVariable variable -> + | FromParamSpec variable -> Canonicalization.parameter_variable_type_representation variable |> Format.asprintf "%a" pp_type | Defined parameters -> @@ -1285,7 +1288,7 @@ module PrettyPrinting = struct let parameters = match parameters with | Undefined -> "..." - | ParameterVariadicTypeVariable variable -> + | FromParamSpec variable -> Canonicalization.parameter_variable_type_representation variable |> Format.asprintf "%a" pp_concise | Defined parameters -> @@ -1372,7 +1375,7 @@ module Parameter = struct let to_variable = function | Single (Variable variable) -> Some (Record.Variable.TypeVarVariable variable) - | CallableParameters (ParameterVariadicTypeVariable { head = []; variable }) -> + | CallableParameters (FromParamSpec { head = []; variable }) -> Some (ParamSpecVariable variable) | Unpacked (Variadic variadic) -> Some (TypeVarTupleVariable variadic) | _ -> None @@ -1587,7 +1590,7 @@ module Callable = struct let parameters { parameters; _ } = match parameters with | Defined parameters -> Some parameters - | ParameterVariadicTypeVariable _ + | FromParamSpec _ | Undefined -> None @@ -2583,7 +2586,7 @@ module Variable = struct let any = Callable.Undefined - let self_reference variable = Callable.ParameterVariadicTypeVariable { head = []; variable } + let self_reference variable = Callable.FromParamSpec { head = []; variable } let pair variable value = ParamSpecPair (variable, value) @@ -2603,17 +2606,17 @@ module Variable = struct let local_replace replacement annotation = let map = function - | Record.Callable.ParameterVariadicTypeVariable { head; variable } -> + | Record.Callable.FromParamSpec { head; variable } -> let open Record.Callable in let apply_head ~head = function - | ParameterVariadicTypeVariable { head = inner_head; variable } -> - ParameterVariadicTypeVariable { head = head @ inner_head; variable } + | FromParamSpec { head = inner_head; variable } -> + FromParamSpec { head = head @ inner_head; variable } | Undefined -> Undefined | Defined tail -> Defined (Callable.prepend_anonymous_parameters ~head ~tail) in replacement variable >>| apply_head ~head - |> Option.value ~default:(ParameterVariadicTypeVariable { head; variable }) + |> Option.value ~default:(FromParamSpec { head; variable }) | parameters -> parameters in match annotation with @@ -2641,15 +2644,13 @@ module Variable = struct let local_collect = function | Callable { implementation; overloads; _ } -> let extract = function - | { Record.Callable.parameters = ParameterVariadicTypeVariable { variable; _ }; _ } -> - Some variable + | { Record.Callable.parameters = FromParamSpec { variable; _ }; _ } -> Some variable | _ -> None in List.filter_map (implementation :: overloads) ~f:extract | Parametric { parameters; _ } -> let extract = function - | Parameter.CallableParameters (ParameterVariadicTypeVariable { variable; _ }) -> - Some variable + | Parameter.CallableParameters (FromParamSpec { variable; _ }) -> Some variable | _ -> None in List.filter_map parameters ~f:extract @@ -3502,7 +3503,7 @@ module ToExpression = struct in Expression.List (List.map ~f:convert_parameter parameters) |> Node.create ~location | Undefined -> Node.create ~location (Expression.Constant Constant.Ellipsis) - | ParameterVariadicTypeVariable variable -> + | FromParamSpec variable -> Canonicalization.parameter_variable_type_representation variable |> expression @@ -4126,8 +4127,7 @@ let rec create_logic ~resolve_aliases ~variable_aliases { Node.value = expressio | Parametric { name; parameters } when List.exists ~f:(Identifier.equal name) Record.OrderedTypes.concatenate_public_names -> ( match List.rev parameters with - | Parameter.CallableParameters (ParameterVariadicTypeVariable { variable; head = [] }) - :: reversed_head -> + | Parameter.CallableParameters (FromParamSpec { variable; head = [] }) :: reversed_head -> Parameter.all_singles reversed_head >>| List.rev >>| fun head -> { Record.Callable.variable; head } @@ -4330,8 +4330,7 @@ let rec create_logic ~resolve_aliases ~variable_aliases { Node.value = expressio | _ -> ( let parsed = create_logic parameters in match substitute_parameter_variadic parsed with - | Some variable -> - make_signature ~parameters:(ParameterVariadicTypeVariable variable) + | Some variable -> make_signature ~parameters:(FromParamSpec variable) | _ -> ( match parsed with | Primitive "..." -> make_signature ~parameters:Undefined @@ -4383,10 +4382,7 @@ let rec create_logic ~resolve_aliases ~variable_aliases { Node.value = expressio | None -> ( match substitute_parameter_variadic parsed with | Some variable -> - [ - Record.Parameter.CallableParameters - (ParameterVariadicTypeVariable variable); - ] + [Record.Parameter.CallableParameters (FromParamSpec variable)] | _ -> [Record.Parameter.Single parsed])) in match subscript_index with @@ -5109,9 +5105,8 @@ let equivalent_for_assert_type left right = let simplify_record_parameters = function | Record.Callable.Defined parameters -> Record.Callable.Defined (simplify_parameters parameters) - | Record.Callable.ParameterVariadicTypeVariable { head; variable } -> - Record.Callable.ParameterVariadicTypeVariable - { head = simplify_parameters head; variable } + | Record.Callable.FromParamSpec { head; variable } -> + Record.Callable.FromParamSpec { head = simplify_parameters head; variable } | needs_no_change -> needs_no_change in let simplify_overload { Record.Callable.annotation; parameters } = diff --git a/source/analysis/type.mli b/source/analysis/type.mli index d1d48642d21..568de8490fb 100644 --- a/source/analysis/type.mli +++ b/source/analysis/type.mli @@ -130,7 +130,7 @@ module Record : sig | Anonymous | Named of Reference.t - and 'annotation parameter_variadic_type_variable = { + and 'annotation params_from_param_spec = { head: 'annotation list; variable: 'annotation Variable.ParamSpec.record; } @@ -138,7 +138,7 @@ module Record : sig and 'annotation record_parameters = | Defined of 'annotation CallableParamType.t list | Undefined - | ParameterVariadicTypeVariable of 'annotation parameter_variadic_type_variable + | FromParamSpec of 'annotation params_from_param_spec and 'annotation overload = { annotation: 'annotation; diff --git a/source/analysis/typeCheck.ml b/source/analysis/typeCheck.ml index 9d03953ff56..92466db5f71 100644 --- a/source/analysis/typeCheck.ml +++ b/source/analysis/typeCheck.ml @@ -159,7 +159,7 @@ let errors_from_not_found Error.InvalidClassInstantiation (Error.AbstractClassInstantiation { class_name; abstract_methods }) ); ] - | CallingParameterVariadicTypeVariable -> [None, Error.NotCallable (Type.Callable callable)] + | CallingFromParamSpec -> [None, Error.NotCallable (Type.Callable callable)] | InvalidKeywordArgument { Node.location; value = { expression; annotation } } -> [ ( Some location, diff --git a/source/analysis/typeConstraints.ml b/source/analysis/typeConstraints.ml index 34bbefebce0..2367af2ecfc 100644 --- a/source/analysis/typeConstraints.ml +++ b/source/analysis/typeConstraints.ml @@ -510,8 +510,7 @@ module OrderedConstraints (Order : OrderType) = struct let is_trivial interval ~variable = match interval with - | Singleton - (Type.Callable.ParameterVariadicTypeVariable { head = []; variable = target_variable }) -> + | Singleton (Type.Callable.FromParamSpec { head = []; variable = target_variable }) -> ParamSpec.equal variable target_variable | _ -> false